[JT] check xor operand is exactly the same in processBranchOnXOR
authorYingchi Long <i@lyc.dev>
Sat, 10 Dec 2022 15:03:26 +0000 (23:03 +0800)
committerYingchi Long <i@lyc.dev>
Wed, 21 Dec 2022 13:43:55 +0000 (21:43 +0800)
commit84733b0f179ecf3fc2c2fa051bf97c7c2ec8f0f9
treefb696aca41b4b5b320b0d6702477bb5d94720612
parent17f804ef4b8fff0e8860ce656f2c4dfbf16d56c6
[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: https://github.com/llvm/llvm-project/issues/58812

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D139783
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/phi-xor-branch.ll [new file with mode: 0644]