[llvm] [AArch64] Use isKnownNonZero to optimize eligible compares to cmn and ccmn (PR #96349)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 21 08:43:51 PDT 2024
AtariDreams wrote:
> This case is now transforming, but I don't believe that is valid:
>
> ```
> define i32 @and_ult_eq_s0s1_or(i32 %s0a, i32 %s1a, i32 %s2, i32 %s3) {
> ; CHECK-LABEL: and_ult_eq_s0s1_or:
> ; CHECK: // %bb.0: // %entry
> ; CHECK-NEXT: orr w8, w1, #0x1
> ; CHECK-NEXT: orr w9, w0, #0x1
> ; CHECK-NEXT: cmp w2, w3
> ; CHECK-NEXT: ccmn w8, w9, #2, eq
> ; CHECK-NEXT: mov w8, #20 // =0x14
> ; CHECK-NEXT: mov w9, #10 // =0xa
> ; CHECK-NEXT: csel w0, w9, w8, lo
> ; CHECK-NEXT: ret
> entry:
> %a1 = or i32 %s0a, 1
> %s1 = or i32 %s1a, 1
> %s0 = sub i32 0, %a1
> %c0 = icmp ult i32 %s0, %s1
> %c1 = icmp eq i32 %s2, %s3
> %a = and i1 %c0, %c1
> %r = select i1 %a, i32 10, i32 20
> ret i32 %r
> }
> ```
It is correct: ccmn w8, w9 can be swapped around while testing for equality: if w8 == -w9, then -w8 == w9.
https://github.com/llvm/llvm-project/pull/96349
More information about the llvm-commits
mailing list