Skip to content

Commit eea05c6

Browse files
committed
[ConstantFolding] Preserve all flags in CastGEPIndices()
This preserves the flags during that transform, but currently they will still end up getting dropped at a later stage.
1 parent 3138c59 commit eea05c6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1,
827827
/// If array indices are not pointer-sized integers, explicitly cast them so
828828
/// that they aren't implicitly casted by the getelementptr.
829829
Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
830-
Type *ResultTy, bool InBounds,
830+
Type *ResultTy, GEPNoWrapFlags NW,
831831
std::optional<ConstantRange> InRange,
832832
const DataLayout &DL, const TargetLibraryInfo *TLI) {
833833
Type *IntIdxTy = DL.getIndexType(ResultTy);
@@ -856,8 +856,8 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
856856
if (!Any)
857857
return nullptr;
858858

859-
Constant *C = ConstantExpr::getGetElementPtr(SrcElemTy, Ops[0], NewIdxs,
860-
InBounds, InRange);
859+
Constant *C =
860+
ConstantExpr::getGetElementPtr(SrcElemTy, Ops[0], NewIdxs, NW, InRange);
861861
return ConstantFoldConstant(C, DL, TLI);
862862
}
863863

@@ -873,7 +873,7 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
873873
if (!SrcElemTy->isSized() || isa<ScalableVectorType>(SrcElemTy))
874874
return nullptr;
875875

876-
if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy, GEP->isInBounds(),
876+
if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy, GEP->getNoWrapFlags(),
877877
GEP->getInRange(), DL, TLI))
878878
return C;
879879

0 commit comments

Comments
 (0)