[llvm] [ValueTracking] Improve tracking for constant range of `{s|u}rem C` (PR #82303)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 23:06:09 PST 2024
================
@@ -8776,13 +8776,26 @@ static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower,
// 'srem x, C' produces (-|C|, |C|).
Upper = C->abs();
Lower = (-Upper) + 1;
+ } else if (match(BO.getOperand(0), m_APInt(C))) {
+ if (C->isNegative()) {
+ // 'srem -|C|, x' produces [-|C|, 0].
+ Upper = 1;
+ Lower = *C;
+ } else {
+ // 'srem |C|, x' produces [0, |C|].
+ Upper = *C + 1;
+ Lower = 0;
----------------
dtcxzyw wrote:
```suggestion
```
https://github.com/llvm/llvm-project/pull/82303
More information about the llvm-commits
mailing list