Skip to content

[X86] Failure to merge BT with matching BTC/BTR/BTS #165291

@RKSimon

Description

@RKSimon
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 }
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 (or BTC/BTS) sets the same EFLAGS CF result as BT (it then clears the bit value afterward) - so we could perform this as:

btr_eq_i32: # @btr_eq_i32  movl (%rdi), %eax  btrl %esi, %eax  movl %eax, (%rdi)  setae %al  retq

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions