Skip to content

Commit d84b0c3

Browse files
committed
[AArch64] Combine SEXT_INREG(CSET) to CSETM.
Add the following patterns to performSignExtendInRegCombine: SIGN_EXTEND_INREG (CSEL 0, 1, cc), i1 --> CSEL 0, -1, cc SIGN_EXTEND_INREG (CSEL 1, 0, cc), i1 --> CSEL -1, 0, cc The combined forms can be matched to a CSETM.
1 parent 82245fc commit d84b0c3

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26585,6 +26585,26 @@ performSignExtendInRegCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
2658526585
return DAG.getNode(SOpc, DL, N->getValueType(0), Ext);
2658626586
}
2658726587

26588+
// Sign extend of CSET -> CSETM.
26589+
if (Opc == AArch64ISD::CSEL &&
26590+
cast<VTSDNode>(N->getOperand(1))->getVT() == MVT::i1) {
26591+
EVT VT = N->getValueType(0);
26592+
SDValue TVal = Src.getOperand(0);
26593+
SDValue FVal = Src.getOperand(1);
26594+
26595+
// SIGN_EXTEND_INREG (CSEL 0, 1, cc), i1 --> CSEL 0, -1, cc
26596+
if (isNullConstant(TVal) && isOneConstant(FVal))
26597+
return DAG.getNode(AArch64ISD::CSEL, DL, VT, TVal,
26598+
DAG.getAllOnesConstant(DL, VT), Src.getOperand(2),
26599+
Src.getOperand(3));
26600+
26601+
// SIGN_EXTEND_INREG (CSEL 1, 0, cc), i1 --> CSEL -1, 0, cc
26602+
if (isOneConstant(TVal) && isNullConstant(FVal))
26603+
return DAG.getNode(AArch64ISD::CSEL, DL, VT,
26604+
DAG.getAllOnesConstant(DL, VT), FVal,
26605+
Src.getOperand(2), Src.getOperand(3));
26606+
}
26607+
2658826608
if (DCI.isBeforeLegalizeOps())
2658926609
return SDValue();
2659026610

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,11 @@ define i64 @select_noccmp2(i64 %v1, i64 %v2, i64 %v3, i64 %r) {
632632
; CHECK-SD-NEXT: cmp x0, #0
633633
; CHECK-SD-NEXT: ccmp x0, #13, #0, pl
634634
; CHECK-SD-NEXT: cset w8, gt
635+
; CHECK-SD-NEXT: csetm w9, gt
635636
; CHECK-SD-NEXT: cmp w8, #0
636637
; CHECK-SD-NEXT: csel x0, xzr, x3, ne
637-
; CHECK-SD-NEXT: sbfx w8, w8, #0, #1
638-
; CHECK-SD-NEXT: adrp x9, _g@PAGE
639-
; CHECK-SD-NEXT: str w8, [x9, _g@PAGEOFF]
638+
; CHECK-SD-NEXT: adrp x8, _g@PAGE
639+
; CHECK-SD-NEXT: str w9, [x8, _g@PAGEOFF]
640640
; CHECK-SD-NEXT: ret
641641
;
642642
; CHECK-GI-LABEL: select_noccmp2:

llvm/test/CodeGen/AArch64/extract-vector-cmp.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,12 @@ for.cond.cleanup:
142142
}
143143

144144

145-
; TODO: Combine the sbfx(cset) into a csetm
146145
define i32 @issue_121372(<4 x i32> %v) {
147146
; CHECK-LABEL: issue_121372:
148147
; CHECK: // %bb.0:
149148
; CHECK-NEXT: fmov w8, s0
150149
; CHECK-NEXT: cmp w8, #0
151-
; CHECK-NEXT: cset w8, eq
152-
; CHECK-NEXT: sbfx w8, w8, #0, #1
150+
; CHECK-NEXT: csetm w8, eq
153151
; CHECK-NEXT: cmp w8, #1
154152
; CHECK-NEXT: csetm w0, lt
155153
; CHECK-NEXT: ret

0 commit comments

Comments
 (0)