[llvm] [AArch64] Add should be adjusted to zero for GlobalISel (PR #195941)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 14:08:22 PDT 2026
https://github.com/LumioseSil created https://github.com/llvm/llvm-project/pull/195941
Realized that we can also get more out of it if it is pl/mi regardless of and, so I put that in SelectionDAG too.
>From 5969aed5adfca71e0d3225c08b1e2761f1ad0b2d Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Tue, 5 May 2026 17:07:48 -0400
Subject: [PATCH] [AArch64] Add should be adjusted to zero for GlobalISel
Realized that we can also get more out of it if it is pl/mi regardless of and, so I put that in SelectionDAG too.
---
.../Target/AArch64/AArch64ISelLowering.cpp | 7 +-
.../GISel/AArch64PostLegalizerLowering.cpp | 84 ++-
...postlegalizer-lowering-adjust-icmp-imm.mir | 8 +-
...galizer-lowering-swap-compare-operands.mir | 4 +-
llvm/test/CodeGen/AArch64/arm64-csel.ll | 27 +-
llvm/test/CodeGen/AArch64/cmp-to-cmn.ll | 640 +++++++++---------
.../CodeGen/AArch64/select-constant-xor.ll | 12 +-
7 files changed, 385 insertions(+), 397 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index f5082b779d1db..8f6354fa06faa 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -4169,11 +4169,8 @@ static unsigned getCmpOperandFoldingProfit(SDValue Op) {
// with 0. Note that this only works for signed comparisons because of how ANDS
// works.
static bool shouldBeAdjustedToZero(SDValue LHS, APInt C, ISD::CondCode &CC) {
- // Only works for ANDS and AND.
- if (LHS.getOpcode() != ISD::AND && LHS.getOpcode() != AArch64ISD::ANDS)
- return false;
-
- if (C.isOne() && (CC == ISD::SETLT || CC == ISD::SETGE)) {
+ if (C.isOne() && (CC == ISD::SETLT || CC == ISD::SETGE) &&
+ (LHS.getOpcode() == ISD::AND || LHS.getOpcode() == AArch64ISD::ANDS)) {
CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT;
return true;
}
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
index 58aa2cc37c9b2..a26cd99af38a3 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
@@ -604,6 +604,31 @@ void applyVAshrLshrImm(MachineInstr &MI, MachineRegisterInfo &MRI,
MI.eraseFromParent();
}
+bool isLegalCmpImmed(APInt C) {
+ // Works for negative immediates too, as it can be written as an ADDS
+ // instruction with a negated immediate.
+ return isLegalArithImmed(C.abs().getZExtValue());
+}
+
+/// Adjust compares against 1/-1 to a compare against 0.
+static bool shouldBeAdjustedToZero(Register LHS, APInt C, CmpInst::Predicate &P,
+ const MachineRegisterInfo &MRI) {
+ MachineInstr *LHSDef = getDefIgnoringCopies(LHS, MRI);
+ const bool IsAndLHS = LHSDef && LHSDef->getOpcode() == TargetOpcode::G_AND;
+
+ if (C.isOne() && (P == CmpInst::ICMP_SLT || P == CmpInst::ICMP_SGE)) {
+ if (!IsAndLHS)
+ return false;
+ P = (P == CmpInst::ICMP_SLT) ? CmpInst::ICMP_SLE : CmpInst::ICMP_SGT;
+ return true;
+ }
+ if (C.isAllOnes() && (P == CmpInst::ICMP_SLE || P == CmpInst::ICMP_SGT)) {
+ P = (P == CmpInst::ICMP_SLE) ? CmpInst::ICMP_SLT : CmpInst::ICMP_SGE;
+ return true;
+ }
+ return false;
+}
+
/// Determine if it is possible to modify the \p RHS and predicate \p P of a
/// G_ICMP instruction such that the right-hand side is an arithmetic immediate.
///
@@ -612,7 +637,7 @@ void applyVAshrLshrImm(MachineInstr &MI, MachineRegisterInfo &MRI,
///
/// \note This assumes that the comparison has been legalized.
std::optional<std::pair<uint64_t, CmpInst::Predicate>>
-tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
+tryAdjustICmpImmAndPred(Register LHS, Register RHS, CmpInst::Predicate P,
const MachineRegisterInfo &MRI) {
const auto &Ty = MRI.getType(RHS);
if (Ty.isVector())
@@ -625,9 +650,12 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
auto ValAndVReg = getIConstantVRegValWithLookThrough(RHS, MRI);
if (!ValAndVReg)
return std::nullopt;
- uint64_t OriginalC = ValAndVReg->Value.getZExtValue();
- uint64_t C = OriginalC;
- if (isLegalArithImmed(C))
+ APInt C = ValAndVReg->Value;
+ APInt OriginalC = C;
+ if (shouldBeAdjustedToZero(LHS, C, P, MRI))
+ return {{0, P}};
+
+ if (isLegalCmpImmed(C))
return std::nullopt;
// We have a non-arithmetic immediate. Check if adjusting the immediate and
@@ -643,11 +671,10 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
// x sge c => x sgt c - 1
//
// When c is not the smallest possible negative number.
- if ((Size == 64 && static_cast<int64_t>(C) == INT64_MIN) ||
- (Size == 32 && static_cast<int32_t>(C) == INT32_MIN))
+ if (C.isMinSignedValue())
return std::nullopt;
P = (P == CmpInst::ICMP_SLT) ? CmpInst::ICMP_SLE : CmpInst::ICMP_SGT;
- C -= 1;
+ C = C - 1;
break;
case CmpInst::ICMP_ULT:
case CmpInst::ICMP_UGE:
@@ -657,9 +684,9 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
// x uge c => x ugt c - 1
//
// When c is not zero.
- assert(C != 0 && "C should not be zero here!");
+ assert(!C.isZero() && "C should not be zero here!");
P = (P == CmpInst::ICMP_ULT) ? CmpInst::ICMP_ULE : CmpInst::ICMP_UGT;
- C -= 1;
+ C = C - 1;
break;
case CmpInst::ICMP_SLE:
case CmpInst::ICMP_SGT:
@@ -669,11 +696,10 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
// x sgt c => s sge c + 1
//
// When c is not the largest possible signed integer.
- if ((Size == 32 && static_cast<int32_t>(C) == INT32_MAX) ||
- (Size == 64 && static_cast<int64_t>(C) == INT64_MAX))
+ if (C.isMaxSignedValue())
return std::nullopt;
P = (P == CmpInst::ICMP_SLE) ? CmpInst::ICMP_SLT : CmpInst::ICMP_SGE;
- C += 1;
+ C = C + 1;
break;
case CmpInst::ICMP_ULE:
case CmpInst::ICMP_UGT:
@@ -683,20 +709,17 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
// x ugt c => s uge c + 1
//
// When c is not the largest possible unsigned integer.
- if ((Size == 32 && static_cast<uint32_t>(C) == UINT32_MAX) ||
- (Size == 64 && C == UINT64_MAX))
+ if (C.isAllOnes())
return std::nullopt;
P = (P == CmpInst::ICMP_ULE) ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE;
- C += 1;
+ C = C + 1;
break;
}
// Check if the new constant is valid, and return the updated constant and
// predicate if it is.
- if (Size == 32)
- C = static_cast<uint32_t>(C);
- if (isLegalArithImmed(C))
- return {{C, P}};
+ if (isLegalCmpImmed(C))
+ return {{C.getZExtValue(), P}};
auto NumberOfInstrToLoadImm = [=](uint64_t Imm) {
SmallVector<AArch64_IMM::ImmInsnModel> Insn;
@@ -704,8 +727,9 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
return Insn.size();
};
- if (NumberOfInstrToLoadImm(OriginalC) > NumberOfInstrToLoadImm(C))
- return {{C, P}};
+ if (NumberOfInstrToLoadImm(OriginalC.getZExtValue()) >
+ NumberOfInstrToLoadImm(C.getZExtValue()))
+ return {{C.getZExtValue(), P}};
return std::nullopt;
}
@@ -722,9 +746,10 @@ bool matchAdjustICmpImmAndPred(
MachineInstr &MI, const MachineRegisterInfo &MRI,
std::pair<uint64_t, CmpInst::Predicate> &MatchInfo) {
assert(MI.getOpcode() == TargetOpcode::G_ICMP);
+ Register LHS = MI.getOperand(2).getReg();
Register RHS = MI.getOperand(3).getReg();
auto Pred = static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
- if (auto MaybeNewImmAndPred = tryAdjustICmpImmAndPred(RHS, Pred, MRI)) {
+ if (auto MaybeNewImmAndPred = tryAdjustICmpImmAndPred(LHS, RHS, Pred, MRI)) {
MatchInfo = *MaybeNewImmAndPred;
return true;
}
@@ -933,15 +958,18 @@ bool trySwapICmpOperands(MachineInstr &MI, MachineRegisterInfo &MRI) {
// can be turned into:
// cmp w12, w11, lsl #1
- // Don't swap if there's a constant on the RHS, because we know we can fold
- // that.
+ // Don't swap if there's a constant on the RHS and it is a legal compare
+ // immediate, because we know we can fold that.
Register RHS = MI.getOperand(3).getReg();
auto RHSCst = getIConstantVRegValWithLookThrough(RHS, MRI);
- if (RHSCst && isLegalArithImmed(RHSCst->Value.getSExtValue()))
+ if (RHSCst && isLegalCmpImmed(RHSCst->Value))
return false;
Register LHS = MI.getOperand(2).getReg();
auto Pred = static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
+ auto IsRegCMN = [&](Register Reg) {
+ return isCMN(getDefIgnoringCopies(Reg, MRI), Pred, MRI);
+ };
auto GetRegForProfit = [&](Register Reg) {
MachineInstr *Def = getDefIgnoringCopies(Reg, MRI);
return isCMN(Def, Pred, MRI) ? Def->getOperand(2).getReg() : Reg;
@@ -949,13 +977,15 @@ bool trySwapICmpOperands(MachineInstr &MI, MachineRegisterInfo &MRI) {
// Don't have a constant on the RHS. If we swap the LHS and RHS of the
// compare, would we be able to fold more instructions?
+ bool LHSIsCMN = IsRegCMN(LHS);
+ bool RHSIsCMN = IsRegCMN(RHS);
Register TheLHS = GetRegForProfit(LHS);
Register TheRHS = GetRegForProfit(RHS);
// If the LHS is more likely to give us a folding opportunity, then swap the
// LHS and RHS.
- return (getCmpOperandFoldingProfit(TheLHS, MRI) >
- getCmpOperandFoldingProfit(TheRHS, MRI));
+ return (getCmpOperandFoldingProfit(TheLHS, MRI) + (LHSIsCMN ? 1 : 0) >
+ getCmpOperandFoldingProfit(TheRHS, MRI) + (RHSIsCMN ? 1 : 0));
}
void applySwapICmpOperands(MachineInstr &MI, GISelChangeObserver &Observer) {
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-adjust-icmp-imm.mir b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-adjust-icmp-imm.mir
index 3b991c3d910d5..a86691b30f44d 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-adjust-icmp-imm.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-adjust-icmp-imm.mir
@@ -649,8 +649,8 @@ body: |
; LOWER-NEXT: {{ $}}
; LOWER-NEXT: %reg0:_(s32) = COPY $w0
; LOWER-NEXT: %reg1:_(s32) = COPY $w1
- ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
- ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg0(s32), [[C]]
+ ; LOWER-NEXT: %cst:_(s32) = G_CONSTANT i32 -1
+ ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %reg0(s32), %cst
; LOWER-NEXT: %select:_(s32) = G_SELECT %cmp(s32), %reg0, %reg1
; LOWER-NEXT: $w0 = COPY %select(s32)
; LOWER-NEXT: RET_ReallyLR implicit $w0
@@ -660,8 +660,8 @@ body: |
; SELECT-NEXT: {{ $}}
; SELECT-NEXT: %reg0:gpr32common = COPY $w0
; SELECT-NEXT: %reg1:gpr32 = COPY $w1
- ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg0, 0, 0, implicit-def $nzcv
- ; SELECT-NEXT: %select:gpr32 = CSELWr %reg0, %reg1, 4, implicit $nzcv
+ ; SELECT-NEXT: [[ADDSWri:%[0-9]+]]:gpr32 = ADDSWri %reg0, 1, 0, implicit-def $nzcv
+ ; SELECT-NEXT: %select:gpr32 = CSELWr %reg0, %reg1, 13, implicit $nzcv
; SELECT-NEXT: $w0 = COPY %select
; SELECT-NEXT: RET_ReallyLR implicit $w0
%reg0:_(s32) = COPY $w0
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-swap-compare-operands.mir b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-swap-compare-operands.mir
index 315ca9360dca6..b7987c2b7cc3f 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-swap-compare-operands.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-lowering-swap-compare-operands.mir
@@ -561,7 +561,7 @@ body: |
; LOWER-NEXT: %sub_rhs:_(i64) = COPY $x0
; LOWER-NEXT: %zero:_(i64) = G_CONSTANT i64 0
; LOWER-NEXT: %cmp_lhs:_(i64) = G_SUB %zero, %sub_rhs
- ; LOWER-NEXT: %cmp:_(i32) = G_ICMP intpred(ne), %cmp_lhs(i64), %cmp_rhs
+ ; LOWER-NEXT: %cmp:_(i32) = G_ICMP intpred(ne), %cmp_rhs(i64), %cmp_lhs
; LOWER-NEXT: $w0 = COPY %cmp(i32)
; LOWER-NEXT: RET_ReallyLR implicit $w0
;
@@ -570,7 +570,7 @@ body: |
; SELECT-NEXT: {{ $}}
; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1
; SELECT-NEXT: %sub_rhs:gpr64 = COPY $x0
- ; SELECT-NEXT: [[ADDSXrr:%[0-9]+]]:gpr64 = ADDSXrr %sub_rhs, %cmp_rhs, implicit-def $nzcv
+ ; SELECT-NEXT: [[ADDSXrr:%[0-9]+]]:gpr64 = ADDSXrr %cmp_rhs, %sub_rhs, implicit-def $nzcv
; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 0, implicit $nzcv
; SELECT-NEXT: $w0 = COPY %cmp
; SELECT-NEXT: RET_ReallyLR implicit $w0
diff --git a/llvm/test/CodeGen/AArch64/arm64-csel.ll b/llvm/test/CodeGen/AArch64/arm64-csel.ll
index f677f2f77fc61..2c7ac20ce68c6 100644
--- a/llvm/test/CodeGen/AArch64/arm64-csel.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-csel.ll
@@ -110,24 +110,15 @@ l.else:
; If CPSR is used multiple times and V flag is used, we don't remove cmp.
define i32 @foo7(i32 %a, i32 %b) nounwind {
-; CHECK-SD-LABEL: foo7:
-; CHECK-SD: // %bb.0: // %entry
-; CHECK-SD-NEXT: subs w8, w0, w1
-; CHECK-SD-NEXT: cneg w9, w8, mi
-; CHECK-SD-NEXT: cmn w8, #1
-; CHECK-SD-NEXT: csel w8, w9, w0, lt
-; CHECK-SD-NEXT: csel w0, w8, w9, gt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: foo7:
-; CHECK-GI: // %bb.0: // %entry
-; CHECK-GI-NEXT: subs w8, w0, w1
-; CHECK-GI-NEXT: cneg w9, w8, mi
-; CHECK-GI-NEXT: cmn w8, #1
-; CHECK-GI-NEXT: csel w10, w9, w0, lt
-; CHECK-GI-NEXT: cmp w8, #0
-; CHECK-GI-NEXT: csel w0, w10, w9, pl
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: foo7:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: subs w8, w0, w1
+; CHECK-NEXT: cneg w9, w8, mi
+; CHECK-NEXT: cmn w8, #1
+; CHECK-NEXT: csel w10, w9, w0, lt
+; CHECK-NEXT: cmp w8, #0
+; CHECK-NEXT: csel w0, w10, w9, pl
+; CHECK-NEXT: ret
entry:
%sub = sub nsw i32 %a, %b
%cmp = icmp sgt i32 %sub, -1
diff --git a/llvm/test/CodeGen/AArch64/cmp-to-cmn.ll b/llvm/test/CodeGen/AArch64/cmp-to-cmn.ll
index b3ce9d2369104..8757f48409827 100644
--- a/llvm/test/CodeGen/AArch64/cmp-to-cmn.ll
+++ b/llvm/test/CodeGen/AArch64/cmp-to-cmn.ll
@@ -5,17 +5,11 @@ target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "arm64"
define i1 @test_EQ_IllEbT(i64 %a, i64 %b) {
-; CHECK-SD-LABEL: test_EQ_IllEbT:
-; CHECK-SD: // %bb.0: // %entry
-; CHECK-SD-NEXT: cmn x0, x1
-; CHECK-SD-NEXT: cset w0, eq
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: test_EQ_IllEbT:
-; CHECK-GI: // %bb.0: // %entry
-; CHECK-GI-NEXT: cmn x1, x0
-; CHECK-GI-NEXT: cset w0, eq
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: test_EQ_IllEbT:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: cmn x0, x1
+; CHECK-NEXT: cset w0, eq
+; CHECK-NEXT: ret
entry:
%add = sub i64 0, %b
%cmp = icmp eq i64 %add, %a
@@ -44,11 +38,19 @@ entry:
}
define i1 @test_EQ_IlsEbT(i64 %a, i16 %b) {
-; CHECK-LABEL: test_EQ_IlsEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x0, w1, sxth
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IlsEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x0, w1, sxth
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IlsEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w1 killed $w1 def $x1
+; CHECK-GI-NEXT: sxth x8, w1
+; CHECK-GI-NEXT: cmn x8, x0
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %b to i64
%add = sub i64 0, %a
@@ -57,11 +59,19 @@ entry:
}
define i1 @test_EQ_IlcEbT(i64 %a, i8 %b) {
-; CHECK-LABEL: test_EQ_IlcEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x0, w1, uxtb
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IlcEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x0, w1, uxtb
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IlcEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w1 killed $w1 def $x1
+; CHECK-GI-NEXT: and x8, x1, #0xff
+; CHECK-GI-NEXT: cmn x8, x0
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %b to i64
%add = sub i64 0, %a
@@ -91,17 +101,11 @@ entry:
}
define i1 @test_EQ_IiiEbT(i32 %a, i32 %b) {
-; CHECK-SD-LABEL: test_EQ_IiiEbT:
-; CHECK-SD: // %bb.0: // %entry
-; CHECK-SD-NEXT: cmn w0, w1
-; CHECK-SD-NEXT: cset w0, eq
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: test_EQ_IiiEbT:
-; CHECK-GI: // %bb.0: // %entry
-; CHECK-GI-NEXT: cmn w1, w0
-; CHECK-GI-NEXT: cset w0, eq
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: test_EQ_IiiEbT:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: cmn w0, w1
+; CHECK-NEXT: cset w0, eq
+; CHECK-NEXT: ret
entry:
%add = sub i32 0, %b
%cmp = icmp eq i32 %add, %a
@@ -109,11 +113,18 @@ entry:
}
define i1 @test_EQ_IisEbT(i32 %a, i16 %b) {
-; CHECK-LABEL: test_EQ_IisEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w0, w1, sxth
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IisEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w0, w1, sxth
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IisEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: sxth w8, w1
+; CHECK-GI-NEXT: cmn w8, w0
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %b to i32
%add = sub i32 0, %a
@@ -122,11 +133,18 @@ entry:
}
define i1 @test_EQ_IicEbT(i32 %a, i8 %b) {
-; CHECK-LABEL: test_EQ_IicEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w0, w1, uxtb
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IicEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w0, w1, uxtb
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IicEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: and w8, w1, #0xff
+; CHECK-GI-NEXT: cmn w8, w0
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %b to i32
%add = sub i32 0, %a
@@ -135,11 +153,19 @@ entry:
}
define i1 @test_EQ_IslEbT(i16 %a, i64 %b) {
-; CHECK-LABEL: test_EQ_IslEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x1, w0, sxth
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IslEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x1, w0, sxth
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IslEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w0 killed $w0 def $x0
+; CHECK-GI-NEXT: sxth x8, w0
+; CHECK-GI-NEXT: cmn x8, x1
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %a to i64
%add = sub i64 0, %b
@@ -148,11 +174,18 @@ entry:
}
define i1 @test_EQ_IsiEbT(i16 %a, i32 %b) {
-; CHECK-LABEL: test_EQ_IsiEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w1, w0, sxth
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IsiEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w1, w0, sxth
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IsiEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: sxth w8, w0
+; CHECK-GI-NEXT: cmn w8, w1
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %a to i32
%add = sub i32 0, %b
@@ -191,11 +224,19 @@ entry:
}
define i1 @test_EQ_IclEbT(i8 %a, i64 %b) {
-; CHECK-LABEL: test_EQ_IclEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x1, w0, uxtb
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IclEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x1, w0, uxtb
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IclEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w0 killed $w0 def $x0
+; CHECK-GI-NEXT: and x8, x0, #0xff
+; CHECK-GI-NEXT: cmn x8, x1
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %a to i64
%add = sub i64 0, %b
@@ -204,11 +245,18 @@ entry:
}
define i1 @test_EQ_IciEbT(i8 %a, i32 %b) {
-; CHECK-LABEL: test_EQ_IciEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w1, w0, uxtb
-; CHECK-NEXT: cset w0, eq
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_EQ_IciEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w1, w0, uxtb
+; CHECK-SD-NEXT: cset w0, eq
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_EQ_IciEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: and w8, w0, #0xff
+; CHECK-GI-NEXT: cmn w8, w1
+; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %a to i32
%add = sub i32 0, %b
@@ -247,17 +295,11 @@ entry:
}
define i1 @test_NE_IllEbT(i64 %a, i64 %b) {
-; CHECK-SD-LABEL: test_NE_IllEbT:
-; CHECK-SD: // %bb.0: // %entry
-; CHECK-SD-NEXT: cmn x0, x1
-; CHECK-SD-NEXT: cset w0, ne
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: test_NE_IllEbT:
-; CHECK-GI: // %bb.0: // %entry
-; CHECK-GI-NEXT: cmn x1, x0
-; CHECK-GI-NEXT: cset w0, ne
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: test_NE_IllEbT:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: cmn x0, x1
+; CHECK-NEXT: cset w0, ne
+; CHECK-NEXT: ret
entry:
%add = sub i64 0, %b
%cmp = icmp ne i64 %add, %a
@@ -286,11 +328,19 @@ entry:
}
define i1 @test_NE_IlsEbT(i64 %a, i16 %b) {
-; CHECK-LABEL: test_NE_IlsEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x0, w1, sxth
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IlsEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x0, w1, sxth
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IlsEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w1 killed $w1 def $x1
+; CHECK-GI-NEXT: sxth x8, w1
+; CHECK-GI-NEXT: cmn x8, x0
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %b to i64
%add = sub i64 0, %a
@@ -299,11 +349,19 @@ entry:
}
define i1 @test_NE_IlcEbT(i64 %a, i8 %b) {
-; CHECK-LABEL: test_NE_IlcEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x0, w1, uxtb
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IlcEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x0, w1, uxtb
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IlcEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w1 killed $w1 def $x1
+; CHECK-GI-NEXT: and x8, x1, #0xff
+; CHECK-GI-NEXT: cmn x8, x0
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %b to i64
%add = sub i64 0, %a
@@ -333,17 +391,11 @@ entry:
}
define i1 @test_NE_IiiEbT(i32 %a, i32 %b) {
-; CHECK-SD-LABEL: test_NE_IiiEbT:
-; CHECK-SD: // %bb.0: // %entry
-; CHECK-SD-NEXT: cmn w0, w1
-; CHECK-SD-NEXT: cset w0, ne
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: test_NE_IiiEbT:
-; CHECK-GI: // %bb.0: // %entry
-; CHECK-GI-NEXT: cmn w1, w0
-; CHECK-GI-NEXT: cset w0, ne
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: test_NE_IiiEbT:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: cmn w0, w1
+; CHECK-NEXT: cset w0, ne
+; CHECK-NEXT: ret
entry:
%add = sub i32 0, %b
%cmp = icmp ne i32 %add, %a
@@ -351,11 +403,18 @@ entry:
}
define i1 @test_NE_IisEbT(i32 %a, i16 %b) {
-; CHECK-LABEL: test_NE_IisEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w0, w1, sxth
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IisEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w0, w1, sxth
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IisEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: sxth w8, w1
+; CHECK-GI-NEXT: cmn w8, w0
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %b to i32
%add = sub i32 0, %a
@@ -364,11 +423,18 @@ entry:
}
define i1 @test_NE_IicEbT(i32 %a, i8 %b) {
-; CHECK-LABEL: test_NE_IicEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w0, w1, uxtb
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IicEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w0, w1, uxtb
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IicEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: and w8, w1, #0xff
+; CHECK-GI-NEXT: cmn w8, w0
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %b to i32
%add = sub i32 0, %a
@@ -377,11 +443,19 @@ entry:
}
define i1 @test_NE_IslEbT(i16 %a, i64 %b) {
-; CHECK-LABEL: test_NE_IslEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x1, w0, sxth
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IslEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x1, w0, sxth
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IslEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w0 killed $w0 def $x0
+; CHECK-GI-NEXT: sxth x8, w0
+; CHECK-GI-NEXT: cmn x8, x1
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %a to i64
%add = sub i64 0, %b
@@ -390,11 +464,18 @@ entry:
}
define i1 @test_NE_IsiEbT(i16 %a, i32 %b) {
-; CHECK-LABEL: test_NE_IsiEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w1, w0, sxth
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IsiEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w1, w0, sxth
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IsiEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: sxth w8, w0
+; CHECK-GI-NEXT: cmn w8, w1
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = sext i16 %a to i32
%add = sub i32 0, %b
@@ -433,11 +514,19 @@ entry:
}
define i1 @test_NE_IclEbT(i8 %a, i64 %b) {
-; CHECK-LABEL: test_NE_IclEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn x1, w0, uxtb
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IclEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn x1, w0, uxtb
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IclEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: // kill: def $w0 killed $w0 def $x0
+; CHECK-GI-NEXT: and x8, x0, #0xff
+; CHECK-GI-NEXT: cmn x8, x1
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %a to i64
%add = sub i64 0, %b
@@ -446,11 +535,18 @@ entry:
}
define i1 @test_NE_IciEbT(i8 %a, i32 %b) {
-; CHECK-LABEL: test_NE_IciEbT:
-; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cmn w1, w0, uxtb
-; CHECK-NEXT: cset w0, ne
-; CHECK-NEXT: ret
+; CHECK-SD-LABEL: test_NE_IciEbT:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: cmn w1, w0, uxtb
+; CHECK-SD-NEXT: cset w0, ne
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: test_NE_IciEbT:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: and w8, w0, #0xff
+; CHECK-GI-NEXT: cmn w8, w1
+; CHECK-GI-NEXT: cset w0, ne
+; CHECK-GI-NEXT: ret
entry:
%conv = zext i8 %a to i32
%add = sub i32 0, %b
@@ -501,281 +597,161 @@ define i1 @cmn_large_imm(i32 %a) {
}
define i1 @almost_immediate_neg_slt(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_slt:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, le
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_slt:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #4097 // =0x1001
-; CHECK-GI-NEXT: movk w8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, lt
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_slt:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, le
+; CHECK-NEXT: ret
%cmp = icmp slt i32 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_slt_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_slt_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, le
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_slt_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-61439 // =0xffffffffffff1001
-; CHECK-GI-NEXT: movk x8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, lt
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_slt_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, le
+; CHECK-NEXT: ret
%cmp = icmp slt i64 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_sge(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sge:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, gt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sge:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #4097 // =0x1001
-; CHECK-GI-NEXT: movk w8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, ge
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sge:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, gt
+; CHECK-NEXT: ret
%cmp = icmp sge i32 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_sge_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sge_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, gt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sge_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-61439 // =0xffffffffffff1001
-; CHECK-GI-NEXT: movk x8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, ge
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sge_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, gt
+; CHECK-NEXT: ret
%cmp = icmp sge i64 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_uge(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_uge:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, hi
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_uge:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #4097 // =0x1001
-; CHECK-GI-NEXT: movk w8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, hs
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_uge:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, hi
+; CHECK-NEXT: ret
%cmp = icmp uge i32 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_uge_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_uge_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, hi
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_uge_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-61439 // =0xffffffffffff1001
-; CHECK-GI-NEXT: movk x8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, hs
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_uge_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, hi
+; CHECK-NEXT: ret
%cmp = icmp uge i64 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_ult(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ult:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, ls
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ult:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #4097 // =0x1001
-; CHECK-GI-NEXT: movk w8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, lo
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ult:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, ls
+; CHECK-NEXT: ret
%cmp = icmp ult i32 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_ult_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ult_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4079, lsl #12 // =16707584
-; CHECK-SD-NEXT: cset w0, ls
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ult_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-61439 // =0xffffffffffff1001
-; CHECK-GI-NEXT: movk x8, #65281, lsl #16
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, lo
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ult_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4079, lsl #12 // =16707584
+; CHECK-NEXT: cset w0, ls
+; CHECK-NEXT: ret
%cmp = icmp ult i64 %x, -16707583
ret i1 %cmp
}
define i1 @almost_immediate_neg_sle(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sle:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, lt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sle:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-16773121 // =0xff000fff
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, le
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sle:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, lt
+; CHECK-NEXT: ret
%cmp = icmp sle i32 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_sle_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sle_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, lt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sle_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-16773121 // =0xffffffffff000fff
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, le
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sle_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, lt
+; CHECK-NEXT: ret
%cmp = icmp sle i64 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_sgt(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sgt:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, ge
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sgt:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-16773121 // =0xff000fff
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, gt
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sgt:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, ge
+; CHECK-NEXT: ret
%cmp = icmp sgt i32 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_sgt_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_sgt_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, ge
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_sgt_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-16773121 // =0xffffffffff000fff
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, gt
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_sgt_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, ge
+; CHECK-NEXT: ret
%cmp = icmp sgt i64 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_ule(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ule:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, lo
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ule:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-16773121 // =0xff000fff
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, ls
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ule:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, lo
+; CHECK-NEXT: ret
%cmp = icmp ule i32 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_ule_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ule_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, lo
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ule_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-16773121 // =0xffffffffff000fff
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, ls
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ule_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, lo
+; CHECK-NEXT: ret
%cmp = icmp ule i64 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_ugt(i32 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ugt:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, hs
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ugt:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-16773121 // =0xff000fff
-; CHECK-GI-NEXT: cmp w0, w8
-; CHECK-GI-NEXT: cset w0, hi
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ugt:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, hs
+; CHECK-NEXT: ret
%cmp = icmp ugt i32 %x, -16773121
ret i1 %cmp
}
define i1 @almost_immediate_neg_ugt_64(i64 %x) {
-; CHECK-SD-LABEL: almost_immediate_neg_ugt_64:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn x0, #4095, lsl #12 // =16773120
-; CHECK-SD-NEXT: cset w0, hs
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: almost_immediate_neg_ugt_64:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov x8, #-16773121 // =0xffffffffff000fff
-; CHECK-GI-NEXT: cmp x0, x8
-; CHECK-GI-NEXT: cset w0, hi
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: almost_immediate_neg_ugt_64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn x0, #4095, lsl #12 // =16773120
+; CHECK-NEXT: cset w0, hs
+; CHECK-NEXT: ret
%cmp = icmp ugt i64 %x, -16773121
ret i1 %cmp
}
@@ -815,17 +791,11 @@ define i1 @cmn_nsw_neg(i32 %a, i32 %b) {
}
define i1 @cmn_swap(i32 %a, i32 %b) {
-; CHECK-SD-LABEL: cmn_swap:
-; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, w1
-; CHECK-SD-NEXT: cset w0, lt
-; CHECK-SD-NEXT: ret
-;
-; CHECK-GI-LABEL: cmn_swap:
-; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: cmn w1, w0
-; CHECK-GI-NEXT: cset w0, lt
-; CHECK-GI-NEXT: ret
+; CHECK-LABEL: cmn_swap:
+; CHECK: // %bb.0:
+; CHECK-NEXT: cmn w0, w1
+; CHECK-NEXT: cset w0, lt
+; CHECK-NEXT: ret
%sub = sub nsw i32 0, %b
%cmp = icmp sgt i32 %sub, %a
ret i1 %cmp
diff --git a/llvm/test/CodeGen/AArch64/select-constant-xor.ll b/llvm/test/CodeGen/AArch64/select-constant-xor.ll
index 97ad579a39f78..53c13fc2abace 100644
--- a/llvm/test/CodeGen/AArch64/select-constant-xor.ll
+++ b/llvm/test/CodeGen/AArch64/select-constant-xor.ll
@@ -155,8 +155,8 @@ define i32 @icmpasreq(i32 %input, i32 %a, i32 %b) {
;
; CHECK-GI-LABEL: icmpasreq:
; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-1 // =0xffffffff
-; CHECK-GI-NEXT: cmp w8, w0, asr #31
+; CHECK-GI-NEXT: asr w8, w0, #31
+; CHECK-GI-NEXT: cmn w8, #1
; CHECK-GI-NEXT: csel w0, w1, w2, eq
; CHECK-GI-NEXT: ret
%sh = ashr i32 %input, 31
@@ -168,14 +168,14 @@ define i32 @icmpasreq(i32 %input, i32 %a, i32 %b) {
define i32 @icmpasrne(i32 %input, i32 %a, i32 %b) {
; CHECK-SD-LABEL: icmpasrne:
; CHECK-SD: // %bb.0:
-; CHECK-SD-NEXT: cmn w0, #1
-; CHECK-SD-NEXT: csel w0, w1, w2, gt
+; CHECK-SD-NEXT: cmp w0, #0
+; CHECK-SD-NEXT: csel w0, w1, w2, pl
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: icmpasrne:
; CHECK-GI: // %bb.0:
-; CHECK-GI-NEXT: mov w8, #-1 // =0xffffffff
-; CHECK-GI-NEXT: cmp w8, w0, asr #31
+; CHECK-GI-NEXT: asr w8, w0, #31
+; CHECK-GI-NEXT: cmn w8, #1
; CHECK-GI-NEXT: csel w0, w1, w2, ne
; CHECK-GI-NEXT: ret
%sh = ashr i32 %input, 31
More information about the llvm-commits
mailing list