Skip to content

Commit b7fe795

Browse files
committed
[InstCombine] Use replaceOperand() in some select transforms
To make sure the old operand is DCEd. NFC apart from worklist order.
1 parent 1ee6ec2 commit b7fe795

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,8 +2696,8 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
26962696
// paths for the values (this helps GetUnderlyingObjects() for example).
26972697
if (TrueSI->getFalseValue() == FalseVal && TrueSI->hasOneUse()) {
26982698
Value *And = Builder.CreateAnd(CondVal, TrueSI->getCondition());
2699-
SI.setOperand(0, And);
2700-
SI.setOperand(1, TrueSI->getTrueValue());
2699+
replaceOperand(SI, 0, And);
2700+
replaceOperand(SI, 1, TrueSI->getTrueValue());
27012701
return &SI;
27022702
}
27032703
}
@@ -2713,8 +2713,8 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
27132713
// select(C0, a, select(C1, a, b)) -> select(C0|C1, a, b)
27142714
if (FalseSI->getTrueValue() == TrueVal && FalseSI->hasOneUse()) {
27152715
Value *Or = Builder.CreateOr(CondVal, FalseSI->getCondition());
2716-
SI.setOperand(0, Or);
2717-
SI.setOperand(2, FalseSI->getFalseValue());
2716+
replaceOperand(SI, 0, Or);
2717+
replaceOperand(SI, 2, FalseSI->getFalseValue());
27182718
return &SI;
27192719
}
27202720
}
@@ -2741,14 +2741,14 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
27412741
canMergeSelectThroughBinop(TrueBO)) {
27422742
if (auto *TrueBOSI = dyn_cast<SelectInst>(TrueBO->getOperand(0))) {
27432743
if (TrueBOSI->getCondition() == CondVal) {
2744-
TrueBO->setOperand(0, TrueBOSI->getTrueValue());
2744+
replaceOperand(*TrueBO, 0, TrueBOSI->getTrueValue());
27452745
Worklist.push(TrueBO);
27462746
return &SI;
27472747
}
27482748
}
27492749
if (auto *TrueBOSI = dyn_cast<SelectInst>(TrueBO->getOperand(1))) {
27502750
if (TrueBOSI->getCondition() == CondVal) {
2751-
TrueBO->setOperand(1, TrueBOSI->getTrueValue());
2751+
replaceOperand(*TrueBO, 1, TrueBOSI->getTrueValue());
27522752
Worklist.push(TrueBO);
27532753
return &SI;
27542754
}
@@ -2761,14 +2761,14 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
27612761
canMergeSelectThroughBinop(FalseBO)) {
27622762
if (auto *FalseBOSI = dyn_cast<SelectInst>(FalseBO->getOperand(0))) {
27632763
if (FalseBOSI->getCondition() == CondVal) {
2764-
FalseBO->setOperand(0, FalseBOSI->getFalseValue());
2764+
replaceOperand(*FalseBO, 0, FalseBOSI->getFalseValue());
27652765
Worklist.push(FalseBO);
27662766
return &SI;
27672767
}
27682768
}
27692769
if (auto *FalseBOSI = dyn_cast<SelectInst>(FalseBO->getOperand(1))) {
27702770
if (FalseBOSI->getCondition() == CondVal) {
2771-
FalseBO->setOperand(1, FalseBOSI->getFalseValue());
2771+
replaceOperand(*FalseBO, 1, FalseBOSI->getFalseValue());
27722772
Worklist.push(FalseBO);
27732773
return &SI;
27742774
}

0 commit comments

Comments
 (0)