[polly] [InstCombine] Canonicalise SextADD + GEP (PR #69581)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 07:11:38 PDT 2023


================
@@ -2335,6 +2335,27 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
       return GetElementPtrInst::Create(GEP.getResultElementType(), NewPtr,
                                        Idx2);
     }
+
+    Value *SIdx;
+    ConstantInt *C;
+    auto SextIntrinsic = dyn_cast<SExtInst>(GEP.getOperand(1));
+    auto AddOp = dyn_cast<BinaryOperator>(SextIntrinsic->getOperand(0));
+    if (match(GEP.getOperand(1), m_OneUse(m_SExt(m_Value(SIdx)))) &&
+        match(SextIntrinsic->getOperand(0),
+              m_OneUse(m_Add(m_Value(Idx1), m_ConstantInt(C)))) &&
+        hasNoSignedWrap(*AddOp)) {
+      // %add = add nsw i32 %idx, C
+      // %sidx = sext i32 %add to i64
+      // %gep = getelementptr i32, i32* %ptr, i64 %sidx
+      // as :
+      // %sidx = sext i32 %idx to i64
+      // %newptr = getelementptr i32, i32* %ptr, i64 %sidx
+      // %newgep = getelementptr i32, i32* %newptr, i64 C
+      auto SIdx1 = Builder.CreateSExt(Idx1, GEP.getOperand(1)->getType());
----------------
LiqinWeng wrote:

the test: loopflatten.ll  is regression?  

https://github.com/llvm/llvm-project/pull/69581


More information about the llvm-commits mailing list