Skip to content

Commit

Permalink
[StructurizeCFG] Fix boolean not bug
Browse files Browse the repository at this point in the history
D118623 added code to fold not-of-compare into a compare
with the inverted predicate, if the compare had no other
uses. This relies on accurate use lists in the IR but it
was run before setPhiValues, when some phi inputs are still
stored in a data structure on the side, instead of being
real uses in the IR. The effect was that a phi that should
be using the original compare result would now get an
inverted result instead.

Fix this by moving simplifyConditions after setPhiValues.

Differential Revision: https://reviews.llvm.org/D120312
  • Loading branch information
jayfoad committed Feb 22, 2022
1 parent cedc23b commit 0e74d75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
Expand Up @@ -1089,8 +1089,8 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
createFlow();
insertConditions(false);
insertConditions(true);
simplifyConditions();
setPhiValues();
simplifyConditions();
simplifyAffectedPhis();
rebuildSSA();

Expand Down
7 changes: 3 additions & 4 deletions llvm/test/Transforms/StructurizeCFG/invert-condition.ll
Expand Up @@ -29,13 +29,12 @@ bb5: ; preds = %bb2
ret void
}

; FIXME: StructurizeCFG modifies I5 in-place without updating the use of I5 in
; the phi instruction.
define void @invert_condition_phi(i32 %arg) {
; CHECK-LABEL: @invert_condition_phi(
; CHECK-NEXT: main_body:
; CHECK-NEXT: [[I5:%.*]] = icmp ne i32 [[ARG:%.*]], 0
; CHECK-NEXT: br i1 [[I5]], label [[IF1:%.*]], label [[ENDIF1:%.*]]
; CHECK-NEXT: [[I5:%.*]] = icmp eq i32 [[ARG:%.*]], 0
; CHECK-NEXT: [[I5_INV:%.*]] = xor i1 [[I5]], true
; CHECK-NEXT: br i1 [[I5_INV]], label [[IF1:%.*]], label [[ENDIF1:%.*]]
; CHECK: if1:
; CHECK-NEXT: br label [[ENDIF1]]
; CHECK: endif1:
Expand Down

0 comments on commit 0e74d75

Please sign in to comment.