Skip to content

[AArch64] Combine cmp + cset into eor #68465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vfdff opened this issue Oct 7, 2023 · 2 comments · Fixed by #68503
Closed

[AArch64] Combine cmp + cset into eor #68465

vfdff opened this issue Oct 7, 2023 · 2 comments · Fixed by #68503

Comments

@vfdff
Copy link
Contributor

vfdff commented Oct 7, 2023

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

@vfdff
Copy link
Contributor Author

vfdff commented Oct 7, 2023

@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2023

@llvm/issue-subscribers-backend-aarch64

* test: https://gcc.godbolt.org/z/19aG7a1ja ``` 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


</details>

vfdff added a commit to vfdff/llvm-project that referenced this issue Oct 9, 2023
This regression triggers after commit f400daa to fix infinite loop issue.

In this case, we can known the shift count is 0, so it will not be
triggered by the form of (iN (~X) u>> (N - 1)) in commit 21d3871, of
which N indicates the data type bitwidth of X.

Fixes llvm#68465
vfdff added a commit that referenced this issue Oct 9, 2023
This regression triggers after commit f400daa to fix infinite loop
issue.

In this case, we can known the shift count is 0, so it will not be
triggered by the form of (iN (~X) u>> (N - 1)) in commit 21d3871, of
which N indicates the data type bitwidth of X.

Fixes #68465.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants