Skip to content

Commit 8ab6164

Browse files
committed
[AArch64] Copy CSNEG, CSINV, and CSINC computeKnownBitsForTargetNode from ARM
1 parent 03a23f0 commit 8ab6164

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,30 @@ void AArch64TargetLowering::computeKnownBitsForTargetNode(
25852585
Known = Known.intersectWith(Known2);
25862586
break;
25872587
}
2588+
case AArch64ISD::CSNEG:
2589+
case AArch64ISD::CSINC:
2590+
case AArch64ISD::CSINV: {
2591+
KnownBits KnownOp0 = DAG.computeKnownBits(Op->getOperand(0), Depth + 1);
2592+
KnownBits KnownOp1 = DAG.computeKnownBits(Op->getOperand(1), Depth + 1);
2593+
2594+
// The result is either:
2595+
// CSINC: KnownOp0 or KnownOp1 + 1
2596+
// CSINV: KnownOp0 or ~KnownOp1
2597+
// CSNEG: KnownOp0 or KnownOp1 * -1
2598+
if (Op.getOpcode() == AArch64ISD::CSINC)
2599+
KnownOp1 = KnownBits::add(
2600+
KnownOp1,
2601+
KnownBits::makeConstant(APInt(Op.getScalarValueSizeInBits(), 1)));
2602+
else if (Op.getOpcode() == AArch64ISD::CSINV)
2603+
std::swap(KnownOp1.Zero, KnownOp1.One);
2604+
else if (Op.getOpcode() == AArch64ISD::CSNEG)
2605+
KnownOp1 =
2606+
KnownBits::mul(KnownOp1, KnownBits::makeConstant(APInt::getAllOnes(
2607+
Op.getScalarValueSizeInBits())));
2608+
2609+
Known = KnownOp0.intersectWith(KnownOp1);
2610+
break;
2611+
}
25882612
case AArch64ISD::BICi: {
25892613
// Compute the bit cleared value.
25902614
APInt Mask =

llvm/test/CodeGen/AArch64/rand.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
define i32 @rndr(ptr %__addr) {
55
; CHECK-LABEL: rndr:
66
; CHECK: // %bb.0:
7-
; CHECK-NEXT: mrs x9, RNDR
8-
; CHECK-NEXT: mov x8, x0
9-
; CHECK-NEXT: cset w10, eq
10-
; CHECK-NEXT: str x9, [x8]
11-
; CHECK-NEXT: and w0, w10, #0x1
7+
; CHECK-NEXT: mrs x10, RNDR
8+
; CHECK-NEXT: mov x9, x0
9+
; CHECK-NEXT: cset w8, eq
10+
; CHECK-NEXT: str x10, [x9]
11+
; CHECK-NEXT: mov w0, w8
1212
; CHECK-NEXT: ret
1313
%1 = tail call { i64, i1 } @llvm.aarch64.rndr()
1414
%2 = extractvalue { i64, i1 } %1, 0
@@ -22,11 +22,11 @@ define i32 @rndr(ptr %__addr) {
2222
define i32 @rndrrs(ptr %__addr) {
2323
; CHECK-LABEL: rndrrs:
2424
; CHECK: // %bb.0:
25-
; CHECK-NEXT: mrs x9, RNDRRS
26-
; CHECK-NEXT: mov x8, x0
27-
; CHECK-NEXT: cset w10, eq
28-
; CHECK-NEXT: str x9, [x8]
29-
; CHECK-NEXT: and w0, w10, #0x1
25+
; CHECK-NEXT: mrs x10, RNDRRS
26+
; CHECK-NEXT: mov x9, x0
27+
; CHECK-NEXT: cset w8, eq
28+
; CHECK-NEXT: str x10, [x9]
29+
; CHECK-NEXT: mov w0, w8
3030
; CHECK-NEXT: ret
3131
%1 = tail call { i64, i1 } @llvm.aarch64.rndrrs()
3232
%2 = extractvalue { i64, i1 } %1, 0

0 commit comments

Comments
 (0)