[llvm] [InstCombine] Add comment on multi-use for indexed compare fold (NFC) (PR #218434)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 08:00:55 PDT 2026
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/218434
>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.
>From f4b68b5339e0817fbc253292b5e68edb570da69c Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Mon, 24 Aug 2026 16:59:16 +0200
Subject: [PATCH] [InstCombine] Add comment on multi-use for indexed compare
fold (NFC)
---
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 5f0b3fb888ecf..7b56820b981fd 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 block guarded
+/// by the icmp.
Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
LoadInst *LI, GetElementPtrInst *GEP, CmpInst &ICI, ConstantInt *AndCst) {
auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(GEP));
More information about the llvm-commits
mailing list