[llvm] [SCCP] Don't allow undef ranges when performing operations (PR #93163)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 03:51:02 PDT 2024
================
@@ -1534,8 +1535,10 @@ void SCCPInstVisitor::visitBinaryOperator(Instruction &I) {
return markOverdefined(&I);
// Try to simplify to a constant range.
- ConstantRange A = getConstantRange(V1State, I.getType());
- ConstantRange B = getConstantRange(V2State, I.getType());
+ ConstantRange A =
+ getConstantRange(V1State, I.getType(), /*UndefAllowed=*/false);
+ ConstantRange B =
----------------
fhahn wrote:
I think the code that uses the constant range information from ValueLatticeElements already should be handling the range-may-include-undef case properly (i.e. not use it when refining instructions, only when using it to replace with a constant).
But it looks like the code below (`mergeInValue` call) simply drops the may-include-undef bit from the operands. If we propagate the bit to the result, things should be fine?
```
- mergeInValue(&I, ValueLatticeElement::getRange(R));
+ mergeInValue(&I, ValueLatticeElement::getRange(
+ R, V1State.isConstantRangeIncludingUndef() ||
+ V2State.isConstantRangeIncludingUndef()));
```
(IIRC the may-inlcude-undef bit was explicitly added to account for cases such as the AND test cases and I was pretty sure this was covered, but perhaps this was a place that got missed)
https://github.com/llvm/llvm-project/pull/93163
More information about the llvm-commits
mailing list