[llvm] [SCCP] Don't allow undef ranges when performing operations (PR #93163)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 04:14:46 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 =
----------------
nikic wrote:
This is the alternative I mentioned in the patch description, and actually what I implemented first. But I think that this will usually produce a worse result than treating undef as a full range.
For example, if you have `zext i8 ([a, b] | undef) to i16` we can either produce `i16 [0, 255]` (this patch) or `i16 ([a, b] | undef)`, where the latter will be interprted as `i16 full-range` in places that don't allow undef. So we can either produce a range that is usable everywhere but is larger, or a range that is only usable in allow-undef contexts but is smaller. As a lot of folds in SCCP don't allow undef, I figured the first variant is preferable.
https://github.com/llvm/llvm-project/pull/93163
More information about the llvm-commits
mailing list