Skip to content

Commit 5d7d89d

Browse files
authored
[AArch64] Use add_and_or_is_add for CSINC (#79552)
Adds or add-like-or's of 1 can both be turned into csinc, which can help fold more instructions into a csinc.
1 parent e33dc6b commit 5d7d89d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ defm CCMP : CondComparison<1, "ccmp", AArch64ccmp>;
26722672
//===----------------------------------------------------------------------===//
26732673
defm CSEL : CondSelect<0, 0b00, "csel">;
26742674

2675-
def inc : PatFrag<(ops node:$in), (add node:$in, 1)>;
2675+
def inc : PatFrag<(ops node:$in), (add_and_or_is_add node:$in, 1)>;
26762676
defm CSINC : CondSelectOp<0, 0b01, "csinc", inc>;
26772677
defm CSINV : CondSelectOp<1, 0b00, "csinv", not>;
26782678
defm CSNEG : CondSelectOp<1, 0b01, "csneg", ineg>;
@@ -2715,9 +2715,9 @@ def : Pat<(AArch64csel (i32 -1), GPR32:$fval, (i32 imm:$cc), NZCV),
27152715
def : Pat<(AArch64csel (i64 -1), GPR64:$fval, (i32 imm:$cc), NZCV),
27162716
(CSINVXr GPR64:$fval, XZR, (i32 (inv_cond_XFORM imm:$cc)))>;
27172717

2718-
def : Pat<(add GPR32:$val, (AArch64csel (i32 0), (i32 1), (i32 imm:$cc), NZCV)),
2718+
def : Pat<(add_and_or_is_add GPR32:$val, (AArch64csel (i32 0), (i32 1), (i32 imm:$cc), NZCV)),
27192719
(CSINCWr GPR32:$val, GPR32:$val, (i32 imm:$cc))>;
2720-
def : Pat<(add GPR64:$val, (zext (AArch64csel (i32 0), (i32 1), (i32 imm:$cc), NZCV))),
2720+
def : Pat<(add_and_or_is_add GPR64:$val, (zext (AArch64csel (i32 0), (i32 1), (i32 imm:$cc), NZCV))),
27212721
(CSINCXr GPR64:$val, GPR64:$val, (i32 imm:$cc))>;
27222722

27232723
def : Pat<(or (topbitsallzero32:$val), (AArch64csel (i32 0), (i32 1), (i32 imm:$cc), NZCV)),

llvm/test/CodeGen/AArch64/arm64-csel.ll

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,9 @@ entry:
423423
define i32 @or(i32 %num, i32 %x) {
424424
; CHECK-LABEL: or:
425425
; CHECK: // %bb.0: // %entry
426-
; CHECK-NEXT: cmp w1, #0
427426
; CHECK-NEXT: and w8, w0, #0xff00
428-
; CHECK-NEXT: cset w9, ne
429-
; CHECK-NEXT: orr w0, w8, w9
427+
; CHECK-NEXT: cmp w1, #0
428+
; CHECK-NEXT: cinc w0, w8, ne
430429
; CHECK-NEXT: ret
431430
entry:
432431
%and = and i32 %num, 65280
@@ -439,10 +438,9 @@ entry:
439438
define i64 @or64(i64 %num, i64 %x) {
440439
; CHECK-LABEL: or64:
441440
; CHECK: // %bb.0: // %entry
442-
; CHECK-NEXT: cmp x1, #0
443441
; CHECK-NEXT: and x8, x0, #0xff00
444-
; CHECK-NEXT: cset w9, ne
445-
; CHECK-NEXT: orr x0, x8, x9
442+
; CHECK-NEXT: cmp x1, #0
443+
; CHECK-NEXT: cinc x0, x8, ne
446444
; CHECK-NEXT: ret
447445
entry:
448446
%and = and i64 %num, 65280
@@ -457,8 +455,7 @@ define i32 @selor32(i32 %num, i32 %x) {
457455
; CHECK: // %bb.0: // %entry
458456
; CHECK-NEXT: and w8, w0, #0xff00
459457
; CHECK-NEXT: cmp w1, #0
460-
; CHECK-NEXT: orr w9, w8, #0x1
461-
; CHECK-NEXT: csel w0, w9, w8, ne
458+
; CHECK-NEXT: cinc w0, w8, ne
462459
; CHECK-NEXT: ret
463460
entry:
464461
%and = and i32 %num, 65280
@@ -489,8 +486,7 @@ define i64 @selor64(i64 %num, i64 %x) {
489486
; CHECK: // %bb.0: // %entry
490487
; CHECK-NEXT: and x8, x0, #0xff00
491488
; CHECK-NEXT: cmp x1, #0
492-
; CHECK-NEXT: orr x9, x8, #0x1
493-
; CHECK-NEXT: csel x0, x9, x8, ne
489+
; CHECK-NEXT: cinc x0, x8, ne
494490
; CHECK-NEXT: ret
495491
entry:
496492
%and = and i64 %num, 65280

0 commit comments

Comments
 (0)