[llvm] 27c4e23 - [InstCombine] Return instruction from replaceUse()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 08:53:13 PDT 2023
Author: Nikita Popov
Date: 2023-03-14T16:53:03+01:00
New Revision: 27c4e233104ba765cd986b3f8b0dcd3a6c3a9f89
URL: https://github.com/llvm/llvm-project/commit/27c4e233104ba765cd986b3f8b0dcd3a6c3a9f89
DIFF: https://github.com/llvm/llvm-project/commit/27c4e233104ba765cd986b3f8b0dcd3a6c3a9f89.diff
LOG: [InstCombine] Return instruction from replaceUse()
Same as with other replacement methods, it's generally necessary
to report a change on the instruction itself, e.g. by returning
it from the visit method (or possibly explicitly adding it to the
worklist).
Return Instruction * from replaceUse() to encourage the usual
"return replaceXYZ" pattern.
Added:
Modified:
llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index a876385581e72..4236544d3ecc4 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -446,9 +446,10 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
}
/// Replace use and add the previously used value to the worklist.
- void replaceUse(Use &U, Value *NewValue) {
+ Instruction *replaceUse(Use &U, Value *NewValue) {
Worklist.addValue(U);
U = NewValue;
+ return cast<Instruction>(U.getUser());
}
/// Combiner aware instruction erasure.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 01249613d47a0..94d3f99156852 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2436,8 +2436,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
assert(isa<AssumeInst>(Assume));
if (isAssumeWithEmptyBundle(*cast<AssumeInst>(II)))
return eraseInstFromFunction(CI);
- replaceUse(II->getOperandUse(0), ConstantInt::getTrue(II->getContext()));
- return nullptr;
+ return replaceUse(II->getOperandUse(0),
+ ConstantInt::getTrue(II->getContext()));
};
// Remove an assume if it is followed by an identical assume.
// TODO: Do we need this? Unless there are conflicting assumptions, the
@@ -2964,10 +2964,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
// Can remove shuffle iff just shuffled elements, no repeats, undefs, or
// other changes.
- if (UsedIndices.all()) {
- replaceUse(II->getOperandUse(ArgIdx), V);
- return nullptr;
- }
+ if (UsedIndices.all())
+ return replaceUse(II->getOperandUse(ArgIdx), V);
break;
}
case Intrinsic::is_fpclass: {
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 1f2441bc9fcf9..fbaf798a0cea8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1251,7 +1251,7 @@ static bool replaceInInstruction(Value *V, Value *Old, Value *New,
bool Changed = false;
for (Use &U : I->operands()) {
if (U == Old) {
- IC.replaceUse(U, New);
+ IC.addToWorklist(IC.replaceUse(U, New));
Changed = true;
} else {
Changed |= replaceInInstruction(U, Old, New, IC, Depth + 1);
More information about the llvm-commits
mailing list