[llvm-branch-commits] [llvm] 7a4f1d5 - [ConstraintElimination] Decompose GEP %ptr, ZEXT(SHL()).

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 1 06:28:41 PST 2020


Author: Florian Hahn
Date: 2020-12-01T14:23:21Z
New Revision: 7a4f1d59b82e5defbce4498347291e6ef9f1281c

URL: https://github.com/llvm/llvm-project/commit/7a4f1d59b82e5defbce4498347291e6ef9f1281c
DIFF: https://github.com/llvm/llvm-project/commit/7a4f1d59b82e5defbce4498347291e6ef9f1281c.diff

LOG: [ConstraintElimination] Decompose GEP %ptr, ZEXT(SHL()).

Add support to decompose a GEP with a ZEXT(SHL()) operand.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
    llvm/test/Transforms/ConstraintElimination/geps.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 5c806b6e5486..8e7480bea284 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -64,6 +64,11 @@ static SmallVector<std::pair<int64_t, Value *>, 4> decompose(Value *V) {
       return {{0, nullptr},
               {1, GEP->getPointerOperand()},
               {pow(2, CI->getSExtValue()), Op0}};
+    if (match(GEP->getOperand(GEP->getNumOperands() - 1),
+              m_ZExt(m_NUWShl(m_Value(Op0), m_ConstantInt(CI)))))
+      return {{0, nullptr},
+              {1, GEP->getPointerOperand()},
+              {pow(2, CI->getSExtValue()), Op0}};
 
     return {{0, nullptr},
             {1, GEP->getPointerOperand()},

diff  --git a/llvm/test/Transforms/ConstraintElimination/geps.ll b/llvm/test/Transforms/ConstraintElimination/geps.ll
index 52aea974294b..a380d5211342 100644
--- a/llvm/test/Transforms/ConstraintElimination/geps.ll
+++ b/llvm/test/Transforms/ConstraintElimination/geps.ll
@@ -455,7 +455,7 @@ define void @test.ult.gep.shl.zext(i32* readonly %src, i32* readnone %max, i32 %
 ; CHECK-NEXT:    [[EXT_1:%.*]] = zext i32 [[IDX_SHL]] to i64
 ; CHECK-NEXT:    [[ADD_PTR_SHL:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 [[EXT_1]]
 ; CHECK-NEXT:    [[C_MAX_0:%.*]] = icmp ult i32* [[ADD_PTR_SHL]], [[MAX]]
-; CHECK-NEXT:    call void @use(i1 [[C_MAX_0]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    [[IDX_SHL_NOT_NUW:%.*]] = shl i32 [[IDX]], 1
 ; CHECK-NEXT:    [[EXT_2:%.*]] = zext i32 [[IDX_SHL_NOT_NUW]] to i64
 ; CHECK-NEXT:    [[ADD_PTR_SHL_NOT_NUW:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 [[EXT_2]]


        


More information about the llvm-branch-commits mailing list