[PATCH] D76931: [ValueLattice] Distinguish between constant ranges with/without undef.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 10:49:56 PDT 2020
fhahn updated this revision to Diff 253634.
fhahn added a comment.
I've adjusted the defaults after rG05f0e598ab26 <https://reviews.llvm.org/rG05f0e598ab265a80fedb23225cde4176f11774ac>: per default, markConstantRange & co assume that the constant range does not contain undef (existing behavior) and isConstantRange/getConstantRange allow constant ranges including undef (existing behavior).
mergeIn automatically marks constant ranges as containing undef based on the merged values. Clients that manually construct ValueLatticeElements are responsible for marking them as containing undef accordingly and also update isConstantRange/getConstantRange calls to exclude ranges including undef where it is not safe. One example is processAnd in CorrelatedValuePropagation, but there will be future changes needed to update all places in LVI that construct lattice elements manually. Currently it uses a helper that returns an optional constant range in multiple places so there's no easy way to recover the information if it may be undef.
I'll also update the example in the description shortly to the code below. %p will be represented as constantrange_including_undef [0, 256) and it would not be allowed to replace %res with %p. Simplifying the condition %f.1 based on range information including undef is allowed, if we replace it with a constant (and remove the original instruction that contained the use of the potentially undef value).
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
}
The changed test cases should give a good idea of the kind of improvements this gives over the singlecr approach.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76931/new/
https://reviews.llvm.org/D76931
Files:
llvm/include/llvm/Analysis/LazyValueInfo.h
llvm/include/llvm/Analysis/ValueLattice.h
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/lib/Analysis/ValueLattice.cpp
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/Attributor/range.ll
llvm/test/Transforms/CorrelatedValuePropagation/merge-range-and-undef.ll
llvm/test/Transforms/SCCP/phi-cycle.ll
llvm/test/Transforms/SCCP/range-and-ip.ll
llvm/test/Transforms/SCCP/range-and.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76931.253634.patch
Type: text/x-patch
Size: 21589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200330/818cac9c/attachment-0001.bin>
More information about the llvm-commits
mailing list