Skip to content

[AArch64] Combine cmp + cset into eor #68465

Closed
@vfdff

Description

@vfdff
static A staticA;
A* Test::aPtr = &staticA;

int main() {
    if (!staticA.isDisabled())
      return 1; 
  return 0;
}
  • clang:
main: // @main
  adrp x8, _ZL7staticA
  ldrb w8, [x8, :lo12:_ZL7staticA]
  cmp w8, #0
  cset w0, eq
  ret
  • gcc:
main:
  adrp x0, .LANCHOR0
  ldrb w0, [x0, #:lo12:.LANCHOR0]
  eor w0, w0, 1
  ret

       .bss
        .align  3
        .set    .LANCHOR0,. + 0
        .type   _ZL7staticA, %object
        .size   _ZL7staticA, 1   ;  ldrb load 1 byte
_ZL7staticA:
        .zero   1

Note:
a) EOR rd, rn, op2 rd = rn ⊕ op2
b) CSET rd, cc if(cc) rd = 1; else rd = 0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions