[all-commits] [llvm/llvm-project] 181628: [SimpleLoopUnswitch] Fix introduction of UB when h...
Juneyoung Lee via All-commits
all-commits at lists.llvm.org
Tue Feb 25 20:47:39 PST 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 181628b52d390f2136fb5a63fe644d230a9b822d
https://github.com/llvm/llvm-project/commit/181628b52d390f2136fb5a63fe644d230a9b822d
Author: Juneyoung Lee <aqjune at gmail.com>
Date: 2020-02-26 (Wed, 26 Feb 2020)
Changed paths:
M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
M llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll
M llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested2.ll
M llvm/test/Transforms/SimpleLoopUnswitch/exponential-switch-unswitch.ll
M llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-cost.ll
M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
Log Message:
-----------
[SimpleLoopUnswitch] Fix introduction of UB when hoisted condition may be undef or poison
Summary:
Loop unswitch hoists branches on loop-invariant conditions. However, if this
condition is poison/undef and the branch wasn't originally reachable, loop
unswitch introduces UB (since the optimized code will branch on poison/undef and
the original one didn't)).
We fix this problem by freezing the condition to ensure we don't introduce UB.
We will now transform the following:
while (...) {
if (C) { A }
else { B }
}
Into:
C' = freeze(C)
if (C') {
while (...) { A }
} else {
while (...) { B }
}
This patch fixes the root cause of the following bug reports (which use the old loop unswitch, but can be reproduced with minor changes in the code and -enable-nontrivial-unswitch):
- https://llvm.org/bugs/show_bug.cgi?id=27506
- https://llvm.org/bugs/show_bug.cgi?id=31652
Reviewers: reames, majnemer, chenli, sanjoy, hfinkel
Reviewed By: reames
Subscribers: hiraditya, jvesely, nhaehnle, filcab, regehr, trentxintong, nlopes, llvm-commits, mzolotukhin
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D29015
More information about the All-commits
mailing list