[llvm] [CVP] Refine results of getConstantRangeAtUse for single users. (PR #211668)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 04:05:57 PDT 2026
================
@@ -2042,7 +2042,22 @@ ConstantRange LazyValueInfo::getConstantRange(Value *V, Instruction *CxtI,
ConstantRange LazyValueInfo::getConstantRangeAtUse(const Use &U,
bool UndefAllowed) {
ValueLatticeElement Result = getOrCreateImpl().getValueAtUse(U);
- return Result.asConstantRange(U->getType(), UndefAllowed);
+ ConstantRange R = Result.asConstantRange(U->getType(), UndefAllowed);
+
+ // If the used value flows into a single user, refine the result using the
+ // range that hold at that user.
+ auto *UserI = cast<Instruction>(U.getUser());
+ if (isa<PHINode>(UserI) ||
+ !isSafeToSpeculativelyExecuteWithVariableReplaced(UserI))
+ return R;
+
+ auto *SingleUser =
+ cast_or_null<Instruction>(UserI->getUniqueUndroppableUser());
+ if (!SingleUser || isa<PHINode>(SingleUser) ||
+ SingleUser->getParent() == UserI->getParent())
+ return R;
+
+ return R.intersectWith(getConstantRange(U, SingleUser, UndefAllowed));
----------------
fhahn wrote:
Yep, but it seems like we can still get the best of both worlds in https://github.com/llvm/llvm-project/pull/212133
https://github.com/llvm/llvm-project/pull/211668
More information about the llvm-commits
mailing list