[llvm] 7fa14a7 - [ConstraintElimination] Decompose GEP with arbitrary offsets.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 14:49:45 PST 2020


Author: Florian Hahn
Date: 2020-11-19T22:49:21Z
New Revision: 7fa14a7c690e8789d964c0d8246e2b3763c4d080

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

LOG: [ConstraintElimination] Decompose GEP with arbitrary offsets.

This patch decomposes `GEP %x, %offset` as  0 + 1 * %x + 1 * %off.

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 251faa0b1825..608ef5337842 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -50,12 +50,16 @@ static SmallVector<std::pair<int64_t, Value *>, 4> decompose(Value *V) {
     return {{CI->getSExtValue(), nullptr}};
   }
   auto *GEP = dyn_cast<GetElementPtrInst>(V);
-  if (GEP && GEP->getNumOperands() == 2 &&
-      isa<ConstantInt>(GEP->getOperand(GEP->getNumOperands() - 1))) {
-    return {{cast<ConstantInt>(GEP->getOperand(GEP->getNumOperands() - 1))
-                 ->getSExtValue(),
-             nullptr},
-            {1, GEP->getPointerOperand()}};
+  if (GEP && GEP->getNumOperands() == 2) {
+    if (isa<ConstantInt>(GEP->getOperand(GEP->getNumOperands() - 1))) {
+      return {{cast<ConstantInt>(GEP->getOperand(GEP->getNumOperands() - 1))
+                   ->getSExtValue(),
+               nullptr},
+              {1, GEP->getPointerOperand()}};
+    }
+    return {{0, nullptr},
+            {1, GEP->getPointerOperand()},
+            {1, GEP->getOperand(GEP->getNumOperands() - 1)}};
   }
 
   Value *Op0;

diff  --git a/llvm/test/Transforms/ConstraintElimination/geps.ll b/llvm/test/Transforms/ConstraintElimination/geps.ll
index cf07d0ba7f72..96a8ce613d55 100644
--- a/llvm/test/Transforms/ConstraintElimination/geps.ll
+++ b/llvm/test/Transforms/ConstraintElimination/geps.ll
@@ -336,7 +336,7 @@ define void @test.not.uge.uge.nonconst(i8* %start, i8* %low, i8* %high, i64 %off
 ; CHECK:       if.then:
 ; CHECK-NEXT:    [[START_OFF_2:%.*]] = getelementptr inbounds i8, i8* [[START]], i64 [[OFF]]
 ; CHECK-NEXT:    [[T_0:%.*]] = icmp uge i8* [[START_OFF_2]], [[HIGH]]
-; CHECK-NEXT:    call void @use(i1 [[T_0]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    ret void
 ; CHECK:       if.end:
 ; CHECK-NEXT:    [[START_1:%.*]] = getelementptr inbounds i8, i8* [[START]], i64 1
@@ -344,7 +344,7 @@ define void @test.not.uge.uge.nonconst(i8* %start, i8* %low, i8* %high, i64 %off
 ; CHECK-NEXT:    call void @use(i1 [[C_0]])
 ; CHECK-NEXT:    [[START_OFF:%.*]] = getelementptr inbounds i8, i8* [[START]], i64 [[OFF]]
 ; CHECK-NEXT:    [[F_0:%.*]] = icmp uge i8* [[START_OFF]], [[HIGH]]
-; CHECK-NEXT:    call void @use(i1 [[F_0]])
+; CHECK-NEXT:    call void @use(i1 false)
 ; CHECK-NEXT:    ret void
 ;
 entry:


        


More information about the llvm-commits mailing list