Skip to content

Commit 97c3c32

Browse files
authored
[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)
The "Size >= 32" check probably dates back to when TableGen integers were 32-bit. Delete it and simplify code by using `isInt`/`isUInt`.
1 parent 74fb992 commit 97c3c32

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

llvm/lib/Target/SystemZ/SystemZInstrInfo.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,10 @@ def IILL : BinaryRI<"iill", 0xA53, insertll, GR32, imm32ll16>;
951951
def IILH : BinaryRI<"iilh", 0xA52, insertlh, GR32, imm32lh16>;
952952
def IIHL : BinaryRI<"iihl", 0xA51, insertll, GRH32, imm32ll16>;
953953
def IIHH : BinaryRI<"iihh", 0xA50, insertlh, GRH32, imm32lh16>;
954-
def IILL64 : BinaryAliasRI<insertll, GR64, imm64ll16>;
955-
def IILH64 : BinaryAliasRI<insertlh, GR64, imm64lh16>;
956-
def IIHL64 : BinaryAliasRI<inserthl, GR64, imm64hl16>;
957-
def IIHH64 : BinaryAliasRI<inserthh, GR64, imm64hh16>;
954+
def IILL64 : BinaryAliasRI<insertll64, GR64, imm64ll16>;
955+
def IILH64 : BinaryAliasRI<insertlh64, GR64, imm64lh16>;
956+
def IIHL64 : BinaryAliasRI<inserthl64, GR64, imm64hl16>;
957+
def IIHH64 : BinaryAliasRI<inserthh64, GR64, imm64hh16>;
958958

959959
// ...likewise for 32-bit immediates. For GR32s this is a general
960960
// full-width move. (We use IILF rather than something like LLILF

llvm/lib/Target/SystemZ/SystemZOperators.td

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,17 @@ defm block_xor : block_op<xor>;
759759
// Insertions.
760760
def inserti8 : PatFrag<(ops node:$src1, node:$src2),
761761
(or (and node:$src1, -256), node:$src2)>;
762-
def insertll : PatFrag<(ops node:$src1, node:$src2),
763-
(or (and node:$src1, 0xffffffffffff0000), node:$src2)>;
764-
def insertlh : PatFrag<(ops node:$src1, node:$src2),
765-
(or (and node:$src1, 0xffffffff0000ffff), node:$src2)>;
766-
def inserthl : PatFrag<(ops node:$src1, node:$src2),
767-
(or (and node:$src1, 0xffff0000ffffffff), node:$src2)>;
768-
def inserthh : PatFrag<(ops node:$src1, node:$src2),
769-
(or (and node:$src1, 0x0000ffffffffffff), node:$src2)>;
762+
763+
class inserti16<int mask> : PatFrag<(ops node:$src1, node:$src2),
764+
(or (and node:$src1, mask), node:$src2)>;
765+
766+
def insertll : inserti16<0xffff0000>;
767+
def insertlh : inserti16<0x0000ffff>;
768+
def insertll64 : inserti16<0xffffffffffff0000>;
769+
def insertlh64 : inserti16<0xffffffff0000ffff>;
770+
def inserthl64 : inserti16<0xffff0000ffffffff>;
771+
def inserthh64 : inserti16<0x0000ffffffffffff>;
772+
770773
def insertlf : PatFrag<(ops node:$src1, node:$src2),
771774
(or (and node:$src1, 0xffffffff00000000), node:$src2)>;
772775
def inserthf : PatFrag<(ops node:$src1, node:$src2),

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,20 +2463,16 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
24632463
// Can only check for types of a known size
24642464
if (VT == MVT::iPTR)
24652465
continue;
2466-
unsigned Size = MVT(VT).getFixedSizeInBits();
2467-
// Make sure that the value is representable for this type.
2468-
if (Size >= 32)
2469-
continue;
2466+
24702467
// Check that the value doesn't use more bits than we have. It must
24712468
// either be a sign- or zero-extended equivalent of the original.
2472-
int64_t SignBitAndAbove = II->getValue() >> (Size - 1);
2473-
if (SignBitAndAbove == -1 || SignBitAndAbove == 0 ||
2474-
SignBitAndAbove == 1)
2475-
continue;
2476-
2477-
TP.error("Integer value '" + Twine(II->getValue()) +
2478-
"' is out of range for type '" + getEnumName(VT) + "'!");
2479-
break;
2469+
unsigned Width = MVT(VT).getFixedSizeInBits();
2470+
int64_t Val = II->getValue();
2471+
if (!isIntN(Width, Val) && !isUIntN(Width, Val)) {
2472+
TP.error("Integer value '" + Twine(Val) +
2473+
"' is out of range for type '" + getEnumName(VT) + "'!");
2474+
break;
2475+
}
24802476
}
24812477
return MadeChange;
24822478
}

0 commit comments

Comments
 (0)