Issue 165291
Summary [X86] Failure to merge BT with matching BTC/BTR/BTS
Labels backend:X86, missed-optimization
Assignees
Reporter RKSimon
    ```ll
define i1 @btr_eq_i32(ptr %word, i32 %position) nounwind {
  %ofs = and i32 %position, 31
  %bit = shl nuw i32 1, %ofs
  %mask = xor i32 %bit, -1
 %ld = load i32, ptr %word
  %test = and i32 %ld, %bit
  %res = and i32 %ld, %mask
  %cmp = icmp eq i32 %test, 0
  store i32 %res, ptr %word
  ret i1 %cmp
}
```
```asm
btr_eq_i32: # @btr_eq_i32
  movl (%rdi), %eax
  movl %eax, %ecx
  btrl %esi, %ecx
  btl %esi, %eax
  setae %al
  movl %ecx, (%rdi)
  retq
```
The BTR sets the same EFLAGS CF result as BT (it then clear the bit value afterward) - so we could perform this as:
```asm
btr_eq_i32: # @btr_eq_i32
  movl (%rdi), %eax
  btrl %esi, %eax
  movl %eax, (%rdi)
  setae %al
  retq
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to