Issue 79315
Summary Redundant equality check when value is known to be 0 or 1
Labels new issue
Assignees
Reporter Sp00ph
    Example:

```ll
declare void @llvm.assume(i1)

define i1 @foo(i8 %a) {
    %lt = icmp ult i8 %a, 2
    tail call void @llvm.assume(i1 %lt)
    %ret = icmp ne i8 %a, 0
    ret i1 %ret
}
```

The `assume` call constrains the value of `%a` to be either 0 or 1, so the function should get compiled to a single `mov al, dil` instruction. Instead, clang produces this redundant instruction sequence:

```asm
foo:
    test    dil, dil
 setne   al
    ret
```

The same thing happens on aarch64, and replacing `icmp ne i8 %a, 0` with `trunc i8 %a to i1` doesn't change the output either.

I discovered this when playing around with inline asm in Rust: https://rust.godbolt.org/z/oafj35dn5 . In this case, the value is set to either 0 or 1 by the `sete` instruction in the asm block, but LLVM inserts two redundant instructions afterwards.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to