[llvm] [polly] [InstCombine] Canonicalise SextADD + GEP (PR #69581)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 01:21:09 PST 2023
================
@@ -2335,6 +2335,20 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
return GetElementPtrInst::Create(GEP.getResultElementType(), NewPtr,
Idx2);
}
+
+ ConstantInt *C;
+ if (match(GEP.getOperand(1), m_OneUse(m_SExt(m_OneUse(m_NSWAdd(
+ m_Value(Idx1), m_ConstantInt(C))))))) {
+ // %add = add nsw i32 %idx1, idx2
+ // %sidx = sext i32 %add to i64
+ // %gep = getelementptr i32, i32* %ptr, i64 %sidx
+ // as :
+ // %newptr = getelementptr i32, i32* %ptr, i32 %idx1
+ // %newgep = getelementptr i32, i32* %newptr, i32 idx2
+ auto *NewPtr = Builder.CreateGEP(GEP.getResultElementType(),
+ GEP.getPointerOperand(), Idx1);
+ return GetElementPtrInst::Create(GEP.getResultElementType(), NewPtr, C);
----------------
nikic wrote:
```suggestion
auto *NewPtr = Builder.CreateGEP(GEP.getResultElementType(),
GEP.getPointerOperand(), Builder.CreateSExt(Idx1));
return GetElementPtrInst::Create(GEP.getResultElementType(), NewPtr, Builder.CreateSExt(C));
```
Make the sexts explicit please.
https://github.com/llvm/llvm-project/pull/69581
More information about the llvm-commits
mailing list