Skip to content

Commit cb5ccab

Browse files
authored
[RISCV][NFC] Simplify Imm range checks (#170497)
1 parent 896288d commit cb5ccab

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ include "RISCV.td"
1717
include "RISCVCombine.td"
1818

1919
def simm12Plus1 : ImmLeaf<XLenVT, [{
20-
return (isInt<12>(Imm) && Imm != -2048) || Imm == 2048;}]>;
20+
return Imm >= -2047 && Imm <= 2048;}]>;
2121
def simm12Plus1i32 : ImmLeaf<i32, [{
22-
return (isInt<12>(Imm) && Imm != -2048) || Imm == 2048;}]>;
22+
return Imm >= -2047 && Imm <= 2048;}]>;
2323

2424
// FIXME: This doesn't check that the G_CONSTANT we're deriving the immediate
2525
// from is only used once
2626
def simm12Minus1Nonzero : ImmLeaf<XLenVT, [{
27-
return (Imm >= -2049 && Imm < 0) || (Imm > 0 && Imm <= 2046);}]>;
27+
return Imm >= -2049 && Imm <= 2046 && Imm != 0;}]>;
2828

2929
def simm12Minus1NonzeroNonNeg1 : ImmLeaf<XLenVT, [{
3030
return (Imm >= -2049 && Imm < -1) || (Imm > 0 && Imm <= 2046);}]>;

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,24 +4315,22 @@ bool RISCVDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &SplatVal) {
43154315
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1(SDValue N, SDValue &SplatVal) {
43164316
return selectVSplatImmHelper(
43174317
N, SplatVal, *CurDAG, *Subtarget,
4318-
[](int64_t Imm) { return (isInt<5>(Imm) && Imm != -16) || Imm == 16; },
4318+
[](int64_t Imm) { return Imm >= -15 && Imm <= 16; },
43194319
/*Decrement=*/true);
43204320
}
43214321

43224322
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1NoDec(SDValue N, SDValue &SplatVal) {
43234323
return selectVSplatImmHelper(
43244324
N, SplatVal, *CurDAG, *Subtarget,
4325-
[](int64_t Imm) { return (isInt<5>(Imm) && Imm != -16) || Imm == 16; },
4325+
[](int64_t Imm) { return Imm >= -15 && Imm <= 16; },
43264326
/*Decrement=*/false);
43274327
}
43284328

43294329
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1NonZero(SDValue N,
43304330
SDValue &SplatVal) {
43314331
return selectVSplatImmHelper(
43324332
N, SplatVal, *CurDAG, *Subtarget,
4333-
[](int64_t Imm) {
4334-
return Imm != 0 && ((isInt<5>(Imm) && Imm != -16) || Imm == 16);
4335-
},
4333+
[](int64_t Imm) { return Imm != 0 && Imm >= -15 && Imm <= 16; },
43364334
/*Decrement=*/true);
43374335
}
43384336

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,7 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
29042904
Ok = isUInt<5>(Imm) && (Imm > 3);
29052905
break;
29062906
case RISCVOp::OPERAND_UIMM5_PLUS1:
2907-
Ok = (isUInt<5>(Imm) && (Imm != 0)) || (Imm == 32);
2907+
Ok = Imm >= 1 && Imm <= 32;
29082908
break;
29092909
case RISCVOp::OPERAND_UIMM6_LSB0:
29102910
Ok = isShiftedUInt<5, 1>(Imm);
@@ -2957,7 +2957,7 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
29572957
CASE_OPERAND_SIMM(26)
29582958
// clang-format on
29592959
case RISCVOp::OPERAND_SIMM5_PLUS1:
2960-
Ok = (isInt<5>(Imm) && Imm != -16) || Imm == 16;
2960+
Ok = Imm >= -15 && Imm <= 16;
29612961
break;
29622962
case RISCVOp::OPERAND_SIMM5_NONZERO:
29632963
Ok = isInt<5>(Imm) && (Imm != 0);

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def ixlenimm_li_restricted : Operand<XLenVT> {
507507

508508
// A 12-bit signed immediate plus one where the imm range will be -2047~2048.
509509
def simm12_plus1 : ImmLeaf<XLenVT,
510-
[{return (isInt<12>(Imm) && Imm != -2048) || Imm == 2048;}]>;
510+
[{return Imm >= -2047 && Imm <= 2048;}]>;
511511

512512
// A 6-bit constant greater than 32.
513513
def uimm6gt32 : ImmLeaf<XLenVT, [{

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ def simm5 : RISCVSImmLeafOp<5> {
7979
}
8080

8181
def simm5_plus1 : RISCVOp, ImmLeaf<XLenVT,
82-
[{return (isInt<5>(Imm) && Imm != -16) || Imm == 16;}]> {
82+
[{return Imm >= -15 && Imm <= 16;}]> {
8383
let ParserMatchClass = SImmAsmOperand<5, "Plus1">;
8484
let OperandType = "OPERAND_SIMM5_PLUS1";
8585
let MCOperandPredicate = [{
8686
int64_t Imm;
8787
if (MCOp.evaluateAsConstantImm(Imm))
88-
return (isInt<5>(Imm) && Imm != -16) || Imm == 16;
88+
return Imm >= -15 && Imm <= 16;
8989
return MCOp.isBareSymbolRef();
9090
}];
9191
}
9292

9393
def simm5_plus1_nonzero : ImmLeaf<XLenVT,
94-
[{return Imm != 0 && ((isInt<5>(Imm) && Imm != -16) || Imm == 16);}]>;
94+
[{return Imm != 0 && Imm >= -15 && Imm <= 16;}]>;
9595

9696
//===----------------------------------------------------------------------===//
9797
// Scheduling definitions.

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def UImm5Plus1AsmOperand : AsmOperandClass {
6262
}
6363

6464
def uimm5_plus1 : RISCVOp, ImmLeaf<XLenVT,
65-
[{return (isUInt<5>(Imm) && (Imm != 0)) || (Imm == 32);}]> {
65+
[{return Imm >= 1 && Imm <= 32;}]> {
6666
let ParserMatchClass = UImm5Plus1AsmOperand;
6767
let EncoderMethod = "getImmOpValueMinus1";
6868
let DecoderMethod = "decodeUImmPlus1Operand<5>";
@@ -71,12 +71,12 @@ def uimm5_plus1 : RISCVOp, ImmLeaf<XLenVT,
7171
int64_t Imm;
7272
if (!MCOp.evaluateAsConstantImm(Imm))
7373
return false;
74-
return (isUInt<5>(Imm) && (Imm != 0)) || (Imm == 32);
74+
return Imm >= 1 && Imm <= 32;
7575
}];
7676
}
7777

7878
def uimm5ge6_plus1 : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
79-
[{return (Imm >= 6) && (isUInt<5>(Imm) || (Imm == 32));}]> {
79+
[{return Imm >= 6 && Imm <= 32;}]> {
8080
let ParserMatchClass = UImmAsmOperand<5, "GE6Plus1">;
8181
let EncoderMethod = "getImmOpValueMinus1";
8282
let DecoderMethod = "decodeUImmPlus1OperandGE<5,6>";
@@ -85,7 +85,7 @@ def uimm5ge6_plus1 : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
8585
int64_t Imm;
8686
if (!MCOp.evaluateAsConstantImm(Imm))
8787
return false;
88-
return (Imm >= 6) && (isUInt<5>(Imm) || (Imm == 32));
88+
return Imm >= 6 && Imm <= 32;
8989
}];
9090
}
9191

0 commit comments

Comments
 (0)