[llvm] 02885ef - [ConstraintElim] Use GEPOperator instead of GetElementPtrInst.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 24 12:16:21 PDT 2023
Author: Florian Hahn
Date: 2023-03-24T19:16:08Z
New Revision: 02885ef3e406ec66fab341e2b98a6fdc8d11322f
URL: https://github.com/llvm/llvm-project/commit/02885ef3e406ec66fab341e2b98a6fdc8d11322f
DIFF: https://github.com/llvm/llvm-project/commit/02885ef3e406ec66fab341e2b98a6fdc8d11322f.diff
LOG: [ConstraintElim] Use GEPOperator instead of GetElementPtrInst.
The logic in ConstraintElimination should trivially apply to GEP
constant expressions as well, so update code to deal with GEPOperator
instead.
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/gep-constexpr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 3d4724e5094d..d0b59d6329fc 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -242,9 +242,8 @@ static bool canUseSExt(ConstantInt *CI) {
}
static Decomposition
-decomposeGEP(GetElementPtrInst &GEP,
- SmallVectorImpl<PreconditionTy> &Preconditions, bool IsSigned,
- const DataLayout &DL) {
+decomposeGEP(GEPOperator &GEP, SmallVectorImpl<PreconditionTy> &Preconditions,
+ bool IsSigned, const DataLayout &DL) {
// Do not reason about pointers where the index size is larger than 64 bits,
// as the coefficients used to encode constraints are 64 bit integers.
if (DL.getIndexTypeSizeInBits(GEP.getPointerOperand()->getType()) > 64)
@@ -264,7 +263,7 @@ decomposeGEP(GetElementPtrInst &GEP,
// Handle the (gep (gep ....), C) case by incrementing the constant
// coefficient of the inner GEP, if C is a constant.
- auto *InnerGEP = dyn_cast<GetElementPtrInst>(GEP.getPointerOperand());
+ auto *InnerGEP = dyn_cast<GEPOperator>(GEP.getPointerOperand());
if (VariableOffsets.empty() && InnerGEP && InnerGEP->getNumOperands() == 2) {
auto Result = decompose(InnerGEP, Preconditions, IsSigned, DL);
Result.add(ConstantOffset.getSExtValue());
@@ -336,7 +335,7 @@ static Decomposition decompose(Value *V,
return int64_t(CI->getZExtValue());
}
- if (auto *GEP = dyn_cast<GetElementPtrInst>(V))
+ if (auto *GEP = dyn_cast<GEPOperator>(V))
return decomposeGEP(*GEP, Preconditions, IsSigned, DL);
Value *Op0;
@@ -808,7 +807,7 @@ static void generateReproducer(CmpInst *Cond, Module *M,
auto *I = dyn_cast<Instruction>(V);
if (Value2Index.contains(V) || !I ||
- !isa<CmpInst, BinaryOperator, GetElementPtrInst, CastInst>(V)) {
+ !isa<CmpInst, BinaryOperator, GEPOperator, CastInst>(V)) {
Old2New[V] = V;
Args.push_back(V);
LLVM_DEBUG(dbgs() << " found external input " << *V << "\n");
diff --git a/llvm/test/Transforms/ConstraintElimination/gep-constexpr.ll b/llvm/test/Transforms/ConstraintElimination/gep-constexpr.ll
index 38dbfc4aa4dc..ff7488673657 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-constexpr.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-constexpr.ll
@@ -13,7 +13,7 @@ define i1 @gep_constexpr_index_lt_upper(i32 noundef %i) {
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[I]] to i64
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds i16, ptr @arr1, i64 [[IDXPROM]]
; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[UPPER]], getelementptr inbounds ([3 x i16], ptr @arr1, i64 1, i64 0)
-; CHECK-NEXT: ret i1 [[C_1]]
+; CHECK-NEXT: ret i1 true
;
entry:
%cmp = icmp ult i32 %i, 3
More information about the llvm-commits
mailing list