[PATCH] D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold.
Hongyu Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 06:42:49 PDT 2023
XChy added a comment.
In D154791#4497148 <https://reviews.llvm.org/D154791#4497148>, @XChy wrote:
> I update the diff to ensure that we fold exactly what can be folded by **foldXorOfICmps** and **foldAndOrOfICmps**.
>
> However, I'm not sure what unexpected result the code below may bring.
>
> // remove the deferred 2 instructions :
> // icmp slt A, 0
> // bitwise (A < 0, icmp)
> // otherwise there will be infinite loops of combining
> Worklist.popDeferred()->eraseFromParent();
> Worklist.popDeferred()->eraseFromParent();
Actually, I copy and edit the code to avoid infinite loops from:
Instruction *eraseInstFromFunction(Instruction &I) override {
LLVM_DEBUG(dbgs() << "IC: ERASE " << I << '\n');
assert(I.use_empty() && "Cannot erase instruction that is used!");
salvageDebugInfo(I);
// Make sure that we reprocess all operands now that we reduced their
// use counts.
SmallVector<Value *> Ops(I.operands());
Worklist.remove(&I);
I.eraseFromParent();
for (Value *Op : Ops)
Worklist.handleUseCountDecrement(Op);
MadeIRChange = true;
return nullptr; // Don't do anything with FI
}
I omit `MadeIRChange = true;` to avoid the infinite loops, which are caused by `MadeIRChange` with the same instructions **deferred and erased**(Actually, IR do not change).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154791/new/
https://reviews.llvm.org/D154791
More information about the llvm-commits
mailing list