[ValueLattice] Distinguish between constant ranges with/without undef.
This patch updates ValueLattice to distinguish between ranges that are guaranteed to not include undef and ranges that may include undef. A constant range guaranteed to not contain undef can be used to simplify instructions to arbitrary values. A constant range that may contain undef can only be used to simplify to a constant. If the value can be undef, it might take a value outside the range. For example, consider the snipped below define i32 @f(i32 %a, i1 %c) { br i1 %c, label %true, label %false true: %a.255 = and i32 %a, 255 br label %exit false: br label %exit exit: %p = phi i32 [ %a.255, %true ], [ undef, %false ] %f.1 = icmp eq i32 %p, 300 call void @use(i1 %f.1) %res = and i32 %p, 255 ret i32 %res } In the exit block, %p would be a constant range [0, 256) including undef as %p could be undef. We can use the range information to replace %f.1 with false because we remove the compare, effectively forcing the use of the constant to be != 300. We cannot replace %res with %p however, because if %a would be undef %cond may be true but the second use might not be < 256. Currently LazyValueInfo uses the new behavior just when simplifying AND instructions and does not distinguish between constant ranges with and without undef otherwise. I think we should address the remaining issues in LVI incrementally. Reviewers: efriedma, reames, aqjune, jdoerfert, sstefan1 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D76931
Showing
- llvm/include/llvm/Analysis/LazyValueInfo.h 3 additions, 1 deletionllvm/include/llvm/Analysis/LazyValueInfo.h
- llvm/include/llvm/Analysis/ValueLattice.h 61 additions, 48 deletionsllvm/include/llvm/Analysis/ValueLattice.h
- llvm/lib/Analysis/LazyValueInfo.cpp 19 additions, 10 deletionsllvm/lib/Analysis/LazyValueInfo.cpp
- llvm/lib/Analysis/ValueLattice.cpp 4 additions, 4 deletionsllvm/lib/Analysis/ValueLattice.cpp
- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp 4 additions, 1 deletionllvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
- llvm/test/Transforms/CorrelatedValuePropagation/merge-range-and-undef.ll 11 additions, 22 deletions...forms/CorrelatedValuePropagation/merge-range-and-undef.ll
- llvm/test/Transforms/SCCP/phi-cycle.ll 33 additions, 0 deletionsllvm/test/Transforms/SCCP/phi-cycle.ll
- llvm/test/Transforms/SCCP/range-and-ip.ll 3 additions, 6 deletionsllvm/test/Transforms/SCCP/range-and-ip.ll
- llvm/test/Transforms/SCCP/range-and.ll 7 additions, 7 deletionsllvm/test/Transforms/SCCP/range-and.ll
Loading
Please register or sign in to comment