Skip to content

Commit b0f53d9

Browse files
authored
[AArch64] Add SUBS(CSEL) fold from brcond. (#142103)
This folds away subs(csel(1, 0, cc)) from brcond, that can be produced in certain places from compares that are not already subs (like adc/sbc generated from i128 add_with_overflow intrinsics).
1 parent c9c6017 commit b0f53d9

14 files changed

+548
-2017
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24668,6 +24668,19 @@ static SDValue performBRCONDCombine(SDNode *N,
2466824668
if (CC != AArch64CC::EQ && CC != AArch64CC::NE)
2466924669
return SDValue();
2467024670

24671+
// Fold away brcond(NE, cmp(csel(1, 0, CC, Cmp), 1)) -> brcond(~CC, Cmp)
24672+
if (isCMP(Cmp) && CC == AArch64CC::NE && isOneConstant(Cmp.getOperand(1))) {
24673+
SDValue CSel = Cmp.getOperand(0);
24674+
auto CSelCC = getCSETCondCode(CSel);
24675+
if (CSelCC) {
24676+
SDLoc DL(N);
24677+
return DAG.getNode(
24678+
N->getOpcode(), DL, N->getVTList(), Chain, Dest,
24679+
DAG.getConstant(getInvertedCondCode(*CSelCC), DL, MVT::i32),
24680+
CSel.getOperand(3));
24681+
}
24682+
}
24683+
2467124684
unsigned CmpOpc = Cmp.getOpcode();
2467224685
if (CmpOpc != AArch64ISD::ADDS && CmpOpc != AArch64ISD::SUBS)
2467324686
return SDValue();

llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lsfe.ll

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,10 @@ define dso_local bfloat @atomicrmw_fsub_bfloat_aligned_monotonic(ptr %ptr, bfloa
451451
; -O0-LABEL: atomicrmw_fsub_bfloat_aligned_monotonic:
452452
; -O0: add w8, w8, w9
453453
; -O0: add w8, w8, w9
454-
; -O0: ldaxrh w9, [x11]
455-
; -O0: cmp w9, w8, uxth
454+
; -O0: ldaxrh w8, [x11]
455+
; -O0: cmp w8, w9, uxth
456456
; -O0: stlxrh w10, w12, [x11]
457-
; -O0: subs w8, w9, w8, uxth
458-
; -O0: subs w8, w8, #1
457+
; -O0: subs w9, w8, w9, uxth
459458
;
460459
; -O1-LABEL: atomicrmw_fsub_bfloat_aligned_monotonic:
461460
; -O1: ldxrh w9, [x0]
@@ -470,11 +469,10 @@ define dso_local bfloat @atomicrmw_fsub_bfloat_aligned_acquire(ptr %ptr, bfloat
470469
; -O0-LABEL: atomicrmw_fsub_bfloat_aligned_acquire:
471470
; -O0: add w8, w8, w9
472471
; -O0: add w8, w8, w9
473-
; -O0: ldaxrh w9, [x11]
474-
; -O0: cmp w9, w8, uxth
472+
; -O0: ldaxrh w8, [x11]
473+
; -O0: cmp w8, w9, uxth
475474
; -O0: stlxrh w10, w12, [x11]
476-
; -O0: subs w8, w9, w8, uxth
477-
; -O0: subs w8, w8, #1
475+
; -O0: subs w9, w8, w9, uxth
478476
;
479477
; -O1-LABEL: atomicrmw_fsub_bfloat_aligned_acquire:
480478
; -O1: ldaxrh w9, [x0]
@@ -489,11 +487,10 @@ define dso_local bfloat @atomicrmw_fsub_bfloat_aligned_release(ptr %ptr, bfloat
489487
; -O0-LABEL: atomicrmw_fsub_bfloat_aligned_release:
490488
; -O0: add w8, w8, w9
491489
; -O0: add w8, w8, w9
492-
; -O0: ldaxrh w9, [x11]
493-
; -O0: cmp w9, w8, uxth
490+
; -O0: ldaxrh w8, [x11]
491+
; -O0: cmp w8, w9, uxth
494492
; -O0: stlxrh w10, w12, [x11]
495-
; -O0: subs w8, w9, w8, uxth
496-
; -O0: subs w8, w8, #1
493+
; -O0: subs w9, w8, w9, uxth
497494
;
498495
; -O1-LABEL: atomicrmw_fsub_bfloat_aligned_release:
499496
; -O1: ldxrh w9, [x0]
@@ -508,11 +505,10 @@ define dso_local bfloat @atomicrmw_fsub_bfloat_aligned_acq_rel(ptr %ptr, bfloat
508505
; -O0-LABEL: atomicrmw_fsub_bfloat_aligned_acq_rel:
509506
; -O0: add w8, w8, w9
510507
; -O0: add w8, w8, w9
511-
; -O0: ldaxrh w9, [x11]
512-
; -O0: cmp w9, w8, uxth
508+
; -O0: ldaxrh w8, [x11]
509+
; -O0: cmp w8, w9, uxth
513510
; -O0: stlxrh w10, w12, [x11]
514-
; -O0: subs w8, w9, w8, uxth
515-
; -O0: subs w8, w8, #1
511+
; -O0: subs w9, w8, w9, uxth
516512
;
517513
; -O1-LABEL: atomicrmw_fsub_bfloat_aligned_acq_rel:
518514
; -O1: ldaxrh w9, [x0]
@@ -527,11 +523,10 @@ define dso_local bfloat @atomicrmw_fsub_bfloat_aligned_seq_cst(ptr %ptr, bfloat
527523
; -O0-LABEL: atomicrmw_fsub_bfloat_aligned_seq_cst:
528524
; -O0: add w8, w8, w9
529525
; -O0: add w8, w8, w9
530-
; -O0: ldaxrh w9, [x11]
531-
; -O0: cmp w9, w8, uxth
526+
; -O0: ldaxrh w8, [x11]
527+
; -O0: cmp w8, w9, uxth
532528
; -O0: stlxrh w10, w12, [x11]
533-
; -O0: subs w8, w9, w8, uxth
534-
; -O0: subs w8, w8, #1
529+
; -O0: subs w9, w8, w9, uxth
535530
;
536531
; -O1-LABEL: atomicrmw_fsub_bfloat_aligned_seq_cst:
537532
; -O1: ldaxrh w9, [x0]

0 commit comments

Comments
 (0)