mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[LoopUnswitch] Simplify branch condition if it is select with constant operands
This fixes the miscompilation reported in https://reviews.llvm.org/rG5bb38e84d3d0#986154 . `select _, true, false` matches both m_LogicalAnd and m_LogicalOr, making later transformations confused. Simplify the branch condition to not have the form.
This commit is contained in:
parent
6da35d08b6
commit
bb16c311ef
@ -2645,6 +2645,13 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
|
||||
BI->getSuccessor(0) == BI->getSuccessor(1))
|
||||
continue;
|
||||
|
||||
// If BI's condition is 'select _, true, false', simplify it to confuse
|
||||
// matchers
|
||||
Value *Cond = BI->getCondition(), *CondNext;
|
||||
while (match(Cond, m_Select(m_Value(CondNext), m_One(), m_Zero())))
|
||||
Cond = CondNext;
|
||||
BI->setCondition(Cond);
|
||||
|
||||
if (L.isLoopInvariant(BI->getCondition())) {
|
||||
UnswitchCandidates.push_back({BI, {BI->getCondition()}});
|
||||
continue;
|
||||
|
@ -4248,7 +4248,7 @@ loop_begin:
|
||||
; CHECK-NEXT: %[[V2:.*]] = load i1, i1* %ptr2
|
||||
; CHECK-NEXT: %[[AND1:.*]] = select i1 %[[V1]], i1 true, i1 false
|
||||
; CHECK-NEXT: %[[AND2:.*]] = select i1 %[[AND1]], i1 true, i1 false
|
||||
; CHECK-NEXT: br i1 %[[AND2]], label %loop_a, label %loop_b
|
||||
; CHECK-NEXT: br i1 %[[V1]], label %loop_a, label %loop_b
|
||||
|
||||
loop_a:
|
||||
call i32 @a()
|
||||
@ -4326,7 +4326,7 @@ loop_begin:
|
||||
; CHECK-NEXT: %[[V2:.*]] = load i1, i1* %ptr2
|
||||
; CHECK-NEXT: %[[AND1:.*]] = select i1 %[[V1]], i1 true, i1 false
|
||||
; CHECK-NEXT: %[[AND2:.*]] = select i1 %[[AND1]], i1 true, i1 false
|
||||
; CHECK-NEXT: br i1 %[[AND2]], label %loop_b, label %loop_a
|
||||
; CHECK-NEXT: br i1 %[[V1]], label %loop_b, label %loop_a
|
||||
|
||||
loop_a:
|
||||
call i32 @a()
|
||||
|
Loading…
Reference in New Issue
Block a user