[llvm] [InstCombine] Remove one-use restriction on icmp of gep fold (PR #76730)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 00:17:37 PST 2024
================
@@ -813,14 +813,28 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
}
}
- // Only lower this if the icmp is the only user of the GEP or if we expect
- // the result to fold to a constant!
- if ((GEPsInBounds || CmpInst::isEquality(Cond)) &&
- (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&
- (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse())) {
+ if (GEPsInBounds || CmpInst::isEquality(Cond)) {
+ auto EmitGEPOffsetAndRewrite = [&](GEPOperator *GEP) {
+ auto *Inst = dyn_cast<Instruction>(GEP);
+ if (Inst)
+ Builder.SetInsertPoint(Inst);
+
+ Value *Offset = EmitGEPOffset(GEP);
+ // If a non-trivial GEP has other uses, rewrite it to avoid duplicating
+ // the offset arithmetic.
+ if (Inst && !GEP->hasOneUse() && !GEP->hasAllConstantIndices()) {
+ replaceInstUsesWith(*Inst,
----------------
nikic wrote:
Done!
https://github.com/llvm/llvm-project/pull/76730
More information about the llvm-commits
mailing list