Skip to content

Commit d8f902d

Browse files
committed
[InstCombine] Remove the canonicalise SextADD + GEP
1 parent 25bea3e commit d8f902d

File tree

3 files changed

+3
-294
lines changed

3 files changed

+3
-294
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,27 +3026,6 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
30263026
GEP, Builder.CreateGEP(GEP.getSourceElementType(), NewPtr, Idx2, "",
30273027
IsInBounds));
30283028
}
3029-
ConstantInt *C;
3030-
if (match(GEP.getOperand(1), m_OneUse(m_SExtLike(m_OneUse(m_NSWAdd(
3031-
m_Value(Idx1), m_ConstantInt(C))))))) {
3032-
// %add = add nsw i32 %idx1, idx2
3033-
// %sidx = sext i32 %add to i64
3034-
// %gep = getelementptr i32, ptr %ptr, i64 %sidx
3035-
// as:
3036-
// %newptr = getelementptr i32, ptr %ptr, i32 %idx1
3037-
// %newgep = getelementptr i32, ptr %newptr, i32 idx2
3038-
bool IsInBounds = CanPreserveInBounds(
3039-
/*IsNSW=*/true, Idx1, C);
3040-
auto *NewPtr = Builder.CreateGEP(
3041-
GEP.getSourceElementType(), GEP.getPointerOperand(),
3042-
Builder.CreateSExt(Idx1, GEP.getOperand(1)->getType()), "",
3043-
IsInBounds);
3044-
return replaceInstUsesWith(
3045-
GEP,
3046-
Builder.CreateGEP(GEP.getSourceElementType(), NewPtr,
3047-
Builder.CreateSExt(C, GEP.getOperand(1)->getType()),
3048-
"", IsInBounds));
3049-
}
30503029
}
30513030

30523031
if (!GEP.isInBounds()) {

llvm/test/Transforms/InstCombine/array.ll

Lines changed: 0 additions & 270 deletions
This file was deleted.

llvm/test/Transforms/InstCombine/gepofconstgepi8.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ define ptr @test_zero_sext_add_nsw(ptr %base, i32 %a) {
8686
; CHECK-SAME: ptr [[BASE:%.*]], i32 [[A:%.*]]) {
8787
; CHECK-NEXT: entry:
8888
; CHECK-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[BASE]], i64 -4
89-
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[A]] to i64
89+
; CHECK-NEXT: [[INDEX:%.*]] = add nsw i32 [[A]], 1
90+
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[INDEX]] to i64
9091
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[P1]], i64 [[TMP0]]
91-
; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[TMP1]], i64 4
92-
; CHECK-NEXT: ret ptr [[P2]]
92+
; CHECK-NEXT: ret ptr [[TMP1]]
9393
;
9494
entry:
9595
%p1 = getelementptr i8, ptr %base, i64 -4

0 commit comments

Comments
 (0)