[llvm] [ValueTracking] Extend LHS/RHS with matching operand to work without constants. (PR #85557)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 00:17:01 PDT 2024
================
@@ -8898,11 +8898,29 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
}
}
- // Can we infer anything when the 0-operands match and the 1-operands are
- // constants (not necessarily matching)?
- const APInt *LC, *RC;
- if (L0 == R0 && match(L1, m_APInt(LC)) && match(R1, m_APInt(RC)))
- return isImpliedCondCommonOperandWithConstants(LPred, *LC, RPred, *RC);
+ // See if we can infer anything if operand-0 matches and we have at least one
+ // constant.
+ const APInt *Unused;
+ if (L0 == R0 && (match(L1, m_APInt(Unused)) || match(R1, m_APInt(Unused)))) {
+ // Potential TODO: We could also further use the constant range of L0/R0 to
+ // further constraint the constant ranges. At the moment this leads to
+ // several regressions related to not transforming `multi_use(A + C0) eq/ne
+ // C1` (see discussion: D58633).
+ ConstantRange LCR = computeConstantRange(
+ L1, ICmpInst::isSigned(LPred), /* UseInstrInfo=*/true, /*AC=*/nullptr,
+ /*CxtI=*/nullptr, /*DT=*/nullptr, MaxAnalysisRecursionDepth - 1);
+ ConstantRange RCR = computeConstantRange(
+ R1, ICmpInst::isSigned(RPred), /* UseInstrInfo=*/true, /*AC=*/nullptr,
+ /*CxtI=*/nullptr, /*DT=*/nullptr, MaxAnalysisRecursionDepth - 1);
+ // Even if L1/R1 are not both constant, we can still sometimes deduce
+ // relationship from a single constant. For example X u> Y implies X != 0.
+ if (auto R = isImpliedCondCommonOperandWithCR(LPred, LCR, RPred, RCR))
+ return R;
+ // If both L1/R1 where exact constant ranges and we didn't get anything
----------------
dtcxzyw wrote:
```suggestion
// If both L1/R1 were exact constant ranges and we didn't get anything
```
https://github.com/llvm/llvm-project/pull/85557
More information about the llvm-commits
mailing list