[llvm] eea05c6 - [ConstantFolding] Preserve all flags in CastGEPIndices()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 01:20:02 PDT 2024
Author: Nikita Popov
Date: 2024-06-04T10:19:52+02:00
New Revision: eea05c6b3369736b703e2a5e3ca08ba6ad8a51dc
URL: https://github.com/llvm/llvm-project/commit/eea05c6b3369736b703e2a5e3ca08ba6ad8a51dc
DIFF: https://github.com/llvm/llvm-project/commit/eea05c6b3369736b703e2a5e3ca08ba6ad8a51dc.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 0cb35c4e0290e..3ca3ae951fcd7 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -827,7 +827,7 @@ Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1,
/// If array indices are not pointer-sized integers, explicitly cast them so
/// that they aren't implicitly casted by the getelementptr.
Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
- Type *ResultTy, bool InBounds,
+ Type *ResultTy, GEPNoWrapFlags NW,
std::optional<ConstantRange> InRange,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
Type *IntIdxTy = DL.getIndexType(ResultTy);
@@ -856,8 +856,8 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
if (!Any)
return nullptr;
- Constant *C = ConstantExpr::getGetElementPtr(SrcElemTy, Ops[0], NewIdxs,
- InBounds, InRange);
+ Constant *C =
+ ConstantExpr::getGetElementPtr(SrcElemTy, Ops[0], NewIdxs, NW, InRange);
return ConstantFoldConstant(C, DL, TLI);
}
@@ -873,7 +873,7 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
if (!SrcElemTy->isSized() || isa<ScalableVectorType>(SrcElemTy))
return nullptr;
- if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy, GEP->isInBounds(),
+ if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy, GEP->getNoWrapFlags(),
GEP->getInRange(), DL, TLI))
return C;
More information about the llvm-commits
mailing list