Skip to content

Commit f368cbc

Browse files
inclycveselypeta
authored andcommitted
[JT] check xor operand is exactly the same in processBranchOnXOR
Reproducer: ; RUN: opt -S -jump-threading < %s define void @test() { entry: br i1 false, label %loop, label %exit loop: %bool = phi i1 [ %xor, %loop.latch ], [ false, %entry ] %cmp = icmp eq i16 0, 1 %xor = xor i1 %cmp, %bool br i1 %bool, label %loop.latch, label %exit loop.latch: %dummy = phi i16 [ 0, %loop ] br label %loop exit: ret void } On this occassion, phi node %bool is actually %xor, and doing substitution causes assertion failure. Fixes: llvm/llvm-project#58812 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D139783
2 parents e3d6990 + 84733b0 commit f368cbc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ bool JumpThreadingPass::processBranchOnXOR(BinaryOperator *BO) {
19311931
// If all preds provide undef, just nuke the xor, because it is undef too.
19321932
BO->replaceAllUsesWith(UndefValue::get(BO->getType()));
19331933
BO->eraseFromParent();
1934-
} else if (SplitVal->isZero()) {
1934+
} else if (SplitVal->isZero() && BO != BO->getOperand(isLHS)) {
19351935
// If all preds provide 0, replace the xor with the other input.
19361936
BO->replaceAllUsesWith(BO->getOperand(isLHS));
19371937
BO->eraseFromParent();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -passes=jump-threading %s | FileCheck %s
3+
4+
; https://github.com/llvm/llvm-project/issues/58812
5+
6+
define void @test() {
7+
; CHECK-LABEL: @test(
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: br label [[EXIT:%.*]]
10+
; CHECK: loop:
11+
; CHECK-NEXT: [[DUMMY:%.*]] = phi i16 [ 0, [[LOOP:%.*]] ]
12+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 0, 1
13+
; CHECK-NEXT: [[XOR:%.*]] = xor i1 false, [[XOR]]
14+
; CHECK-NEXT: br i1 [[XOR]], label [[LOOP]], label [[EXIT]]
15+
; CHECK: exit:
16+
; CHECK-NEXT: ret void
17+
;
18+
entry:
19+
br i1 false, label %loop, label %exit
20+
21+
loop:
22+
%bool = phi i1 [ %xor, %loop.latch ], [ false, %entry ]
23+
%cmp = icmp eq i16 0, 1
24+
%xor = xor i1 %cmp, %bool
25+
br i1 %bool, label %loop.latch, label %exit
26+
27+
loop.latch:
28+
%dummy = phi i16 [ 0, %loop ]
29+
br label %loop
30+
31+
exit:
32+
ret void
33+
}

0 commit comments

Comments
 (0)