Skip to content

Commit 966435d

Browse files
committed
[AArch64] Fold CSEL x, x, cc -> x
This can come up in rare situations, where a csel is created with identical operands. These can be folded simply to the original value, allowing the csel to be removed and further simplification to happen. This patch also removes FCSEL as it is unused, not being produced anywhere or lowered to anything. Differential Revision: https://reviews.llvm.org/D101687
1 parent b2be167 commit 966435d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,6 @@ const char *AArch64TargetLowering::getTargetNodeName(unsigned Opcode) const {
18061806
MAKE_CASE(AArch64ISD::RET_FLAG)
18071807
MAKE_CASE(AArch64ISD::BRCOND)
18081808
MAKE_CASE(AArch64ISD::CSEL)
1809-
MAKE_CASE(AArch64ISD::FCSEL)
18101809
MAKE_CASE(AArch64ISD::CSINV)
18111810
MAKE_CASE(AArch64ISD::CSNEG)
18121811
MAKE_CASE(AArch64ISD::CSINC)
@@ -15156,6 +15155,17 @@ static SDValue performBRCONDCombine(SDNode *N,
1515615155
return SDValue();
1515715156
}
1515815157

15158+
// Optimize CSEL instructions
15159+
static SDValue performCSELCombine(SDNode *N,
15160+
TargetLowering::DAGCombinerInfo &DCI,
15161+
SelectionDAG &DAG) {
15162+
// CSEL x, x, cc -> x
15163+
if (N->getOperand(0) == N->getOperand(1))
15164+
return N->getOperand(0);
15165+
15166+
return performCONDCombine(N, DCI, DAG, 2, 3);
15167+
}
15168+
1515915169
// Optimize some simple tbz/tbnz cases. Returns the new operand and bit to test
1516015170
// as well as whether the test should be inverted. This code is required to
1516115171
// catch these cases (as opposed to standard dag combines) because
@@ -15949,7 +15959,7 @@ SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N,
1594915959
case AArch64ISD::TBZ:
1595015960
return performTBZCombine(N, DCI, DAG);
1595115961
case AArch64ISD::CSEL:
15952-
return performCONDCombine(N, DCI, DAG, 2, 3);
15962+
return performCSELCombine(N, DCI, DAG);
1595315963
case AArch64ISD::DUP:
1595415964
return performPostLD1Combine(N, DCI, false);
1595515965
case AArch64ISD::NVCAST:

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ enum NodeType : unsigned {
6666
RET_FLAG, // Return with a flag operand. Operand 0 is the chain operand.
6767
BRCOND, // Conditional branch instruction; "b.cond".
6868
CSEL,
69-
FCSEL, // Conditional move instruction.
7069
CSINV, // Conditional select invert.
7170
CSNEG, // Conditional select negate.
7271
CSINC, // Conditional select increment.

llvm/test/CodeGen/AArch64/srem-seteq.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ define i32 @test_srem_int_min(i32 %X) nounwind {
269269
define i32 @test_srem_allones(i32 %X) nounwind {
270270
; CHECK-LABEL: test_srem_allones:
271271
; CHECK: // %bb.0:
272-
; CHECK-NEXT: cmp w0, #0 // =0
273-
; CHECK-NEXT: csel w8, w0, w0, lt
274-
; CHECK-NEXT: cmp w0, w8
275-
; CHECK-NEXT: cset w0, eq
272+
; CHECK-NEXT: mov w0, #1
276273
; CHECK-NEXT: ret
277274
%srem = srem i32 %X, 4294967295
278275
%cmp = icmp eq i32 %srem, 0

0 commit comments

Comments
 (0)