Skip to content

Commit 828d72b

Browse files
authored
[GlobalISel] Add an assert for the DemandedElts APInt size. (#112150)
Similar to the other implementations in DAG/ValueTracking, this adds an assert that the size of the DemandedElts is what we expect it to be - the size of a fixed length vector or APInt(1,1) otherwise. The G_BUILDVECTOR is fixed as it was passing an original DemandedElts for the scalar operands.
1 parent 3dba5d8 commit 828d72b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
148148
unsigned Opcode = MI.getOpcode();
149149
LLT DstTy = MRI.getType(R);
150150

151+
#ifndef NDEBUG
152+
if (DstTy.isFixedVector()) {
153+
assert(
154+
DstTy.getNumElements() == DemandedElts.getBitWidth() &&
155+
"DemandedElt width should equal the fixed vector number of elements");
156+
} else {
157+
assert(DemandedElts.getBitWidth() == 1 && DemandedElts == APInt(1, 1) &&
158+
"DemandedElt width should be 1 for scalars or scalable vectors");
159+
}
160+
#endif
161+
151162
// Handle the case where this is called on a register that does not have a
152163
// type constraint (i.e. it has a register class constraint instead). This is
153164
// unlikely to occur except by looking through copies but it is possible for
@@ -196,7 +207,7 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
196207
if (!DemandedElts[i])
197208
continue;
198209

199-
computeKnownBitsImpl(MI.getOperand(i + 1).getReg(), Known2, DemandedElts,
210+
computeKnownBitsImpl(MI.getOperand(i + 1).getReg(), Known2, APInt(1, 1),
200211
Depth + 1);
201212

202213
// Known bits are the values that are shared by every demanded element.

0 commit comments

Comments
 (0)