| Issue |
244708
|
| Summary |
[InstCombine] Missed fold: or (select C, (X & 112), 112), (X & -113) -> or X, (select C, 0, 112)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Leo0506
|
If `C` is true, the result is `(X & 112) | (X & -113) = X`;
if `C` is false, it is `112 | (X & -113) = X | 112`.
So it is `X | (C ? 0 : 112)`. On trunk, `opt -O3` keeps both `and`s, the `select` and the `or`.
```llvm
define i8 @src(i1 %c, i8 %x) {
%m = and i8 %x, 112
%s = select i1 %c, i8 %m, i8 112
%lo = and i8 %x, -113
%r = or disjoint i8 %s, %lo
ret i8 %r
}
define i8 @tgt(i1 %c, i8 %x) {
%s = select i1 %c, i8 0, i8 112
%r = or i8 %x, %s
ret i8 %r
}
```
Alive2 proof: https://alive2.llvm.org/ce/z/5ixcjc
x86-64 (`llc -O3`), current vs. expected:
```asm
movl %esi, %eax xorl %ecx, %ecx
movl %esi, %ecx testb $1, %dil
andl $112, %ecx movl $112, %eax
testb $1, %dil cmovnel %ecx, %eax
movl $112, %edx orl %esi, %eax
cmovnel %ecx, %edx
andb $-113, %al
orb %dl, %al
```
https://godbolt.org/z/qxf91W5Eo
Found in real code: Linux v7.2-rc6 (the version built by llvm-opt-benchmark),
`include/linux/skbuff.h:1218`, function `skb_dst_set()`:
https://github.com/torvalds/linux/blob/v7.2-rc6/include/linux/skbuff.h#L1218
The line is `skb->slow_gro |= !!dst;`, where `slow_gro` is a 1-bit bitfield, so the
containing i32 word is updated with M = 0x200000.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs