Skip to content

Commit fdf21a8

Browse files
committed
Do scale in uint64_t and assert shift amount < 64
Also assert that 64 * LMUL / SEW > 0, so if the scale is shifted down to 0 then the equality check should always be false.
1 parent 7076460 commit fdf21a8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ bool RISCVVectorPeephole::convertToVLMAX(MachineInstr &MI) const {
8989
return false;
9090

9191
// Fixed-point value, denominator=8
92-
unsigned ScaleFixed = 8;
92+
uint64_t ScaleFixed = 8;
9393
// Check if the VLENB was potentially scaled with slli/srli
9494
if (Def->getOpcode() == RISCV::SLLI) {
95+
assert(Def->getOperand(2).getImm() < 64);
9596
ScaleFixed <<= Def->getOperand(2).getImm();
9697
Def = MRI->getVRegDef(Def->getOperand(1).getReg());
9798
} else if (Def->getOpcode() == RISCV::SRLI) {
99+
assert(Def->getOperand(2).getImm() < 64);
98100
ScaleFixed >>= Def->getOperand(2).getImm();
99101
Def = MRI->getVRegDef(Def->getOperand(1).getReg());
100102
}
@@ -109,6 +111,7 @@ bool RISCVVectorPeephole::convertToVLMAX(MachineInstr &MI) const {
109111
// A Log2SEW of 0 is an operation on mask registers only
110112
unsigned SEW = Log2SEW ? 1 << Log2SEW : 8;
111113
assert(RISCVVType::isValidSEW(SEW) && "Unexpected SEW");
114+
assert(8 * LMULFixed / SEW > 0);
112115

113116
// AVL = (VLENB * Scale)
114117
//

0 commit comments

Comments
 (0)