| Issue |
174937
|
| Summary |
LLVM does not optimize (c & a) | (!c & b) into select %c, %a, %b
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mikaseianatsu
|
**Description:**
I found that LLVM does not simplify below expressions into a `select` instruction.
**Input Program**
```
define i1 @bools2_logical_commute0_and1(i1 %a, i1 %b, i1 %c){
%not = xor i1 %c, true
%and1 = and i1 %c, %a
%and2 = select i1 %not, i1 %b, i1 false
%or1 = or i1 %and1, %and2
ret i1 %or1
}
```
The first input program can be optimized by LLVM to the form shown below, as the whole sequence `(c & a) | (!c & b)` can be simplified to `select %c, %a, %b`.
```
define i1 @bools2_logical_commute0_and1(i1 %a, i1 %b, i1 %c){
%or = select i1 %c, i1 %a, i1 %b
ret i1 %or
}
```
However, in the given input program, LLVM fails to recognize this pattern. Even when applying high-level optimization passes such as -O2 or -O3, the IR remains in its original form.This seems like a missed optimization opportunity in InstCombine or related passes.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs