[llvm] [InstCombine] Add comment on multi-use for indexed compare fold (NFC) (PR #218434)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 08:01:53 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
>From the experiment in https://github.com/llvm/llvm-project/pull/151524, restricting the fold to one-use does not appear to be beneficial in practice. Leave a comment mentioning this.
---
Full diff: https://github.com/llvm/llvm-project/pull/218434.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+5)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 5f0b3fb888ecf..dcae505450941 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -115,6 +115,11 @@ static bool isSignTest(ICmpInst::Predicate &Pred, const APInt &C) {
///
/// If AndCst is non-null, then the loaded value is masked with that constant
/// before doing the comparison. This handles cases like "A[i]&4 == 0".
+///
+/// We allow multi-use cases in this fold, even though it can increase
+/// instruction count, because it appears to be mostly beneficial in practice.
+/// Even if there are multiple uses, they can often be sunk into the block
+/// guarded by the icmp.
Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
LoadInst *LI, GetElementPtrInst *GEP, CmpInst &ICI, ConstantInt *AndCst) {
auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(GEP));
``````````
</details>
https://github.com/llvm/llvm-project/pull/218434
More information about the llvm-commits
mailing list