Skip to content

Commit 30d7121

Browse files
committed
[InstCombine] Use replaceOperand() API in GEP transforms
To make sure that replaced operands get DCEd. This drops one iteration from gepphigep.ll, which is still not optimal. This was the last test case performing more than 3 iterations. NFC-ish, only worklist order should change.
1 parent b1f78ba commit 30d7121

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
19961996

19971997
GEP.getParent()->getInstList().insert(
19981998
GEP.getParent()->getFirstInsertionPt(), NewGEP);
1999-
GEP.setOperand(0, NewGEP);
1999+
replaceOperand(GEP, 0, NewGEP);
20002000
PtrOp = NewGEP;
20012001
}
20022002

@@ -2096,8 +2096,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
20962096
// Update the GEP in place if possible.
20972097
if (Src->getNumOperands() == 2) {
20982098
GEP.setIsInBounds(isMergedGEPInBounds(*Src, *cast<GEPOperator>(&GEP)));
2099-
GEP.setOperand(0, Src->getOperand(0));
2100-
GEP.setOperand(1, Sum);
2099+
replaceOperand(GEP, 0, Src->getOperand(0));
2100+
replaceOperand(GEP, 1, Sum);
21012101
return &GEP;
21022102
}
21032103
Indices.append(Src->op_begin()+1, Src->op_end()-1);
@@ -2215,9 +2215,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
22152215
// array. Because the array type is never stepped over (there
22162216
// is a leading zero) we can fold the cast into this GEP.
22172217
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
2218-
GEP.setOperand(0, StrippedPtr);
22192218
GEP.setSourceElementType(XATy);
2220-
return &GEP;
2219+
return replaceOperand(GEP, 0, StrippedPtr);
22212220
}
22222221
// Cannot replace the base pointer directly because StrippedPtr's
22232222
// address space is different. Instead, create a new GEP followed by

llvm/test/Transforms/InstCombine/gepphigep.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -instcombine -S < %s | FileCheck %s
1+
; RUN: opt -instcombine -instcombine-infinite-loop-threshold=3 -S < %s | FileCheck %s
22

33
%struct1 = type { %struct2*, i32, i32, i32 }
44
%struct2 = type { i32, i32 }

0 commit comments

Comments
 (0)