[llvm] ValueTracking: complete matchSimpleRecurrence (PR #108973)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 17:38:43 PDT 2024
================
@@ -1514,9 +1514,26 @@ static void computeKnownBitsFromOperator(const Operator *I,
Known3.isNonNegative())
Known.makeNonNegative();
}
-
break;
}
+ case Instruction::UDiv:
+ case Instruction::URem:
+ // Result cannot be larger than start value.
+ Known.Zero.setHighBits(Known2.countMinLeadingZeros());
+ break;
+ case Instruction::SDiv:
+ case Instruction::SRem: {
+ // Magnitude of result cannot be larger than that of start value.
+ if (Known2.isNonNegative())
+ Known.Zero.setHighBits(Known2.countMinLeadingZeros());
+ else if (Known2.isNegative())
+ Known.One.setHighBits(Known2.countMinLeadingOnes());
----------------
dtcxzyw wrote:
Is it correct? A counterexample: `for (int i = -9; cond; i /= 7)`.
The phi node should be known to be non-zero. I prefer to drop the `Known2.isNegative()` case.
https://github.com/llvm/llvm-project/pull/108973
More information about the llvm-commits
mailing list