Skip to content

Commit fc93690

Browse files
[CIR] Changed test around and added more comments
1 parent 057fd70 commit fc93690

File tree

2 files changed

+115
-198
lines changed

2 files changed

+115
-198
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,25 @@ static mlir::Value emitX86SExtMask(CIRGenFunction &cgf, mlir::Value op,
161161
static mlir::Value emitX86PSLLDQIByteShift(CIRGenFunction &cgf,
162162
const CallExpr *E,
163163
ArrayRef<mlir::Value> Ops) {
164-
165164
auto &builder = cgf.getBuilder();
166-
auto loc = cgf.getLoc(E->getExprLoc());
167-
168165
unsigned shiftVal = getIntValueFromConstOp(Ops[1]) & 0xff;
166+
auto loc = cgf.getLoc(E->getExprLoc());
169167
auto resultType = cast<cir::VectorType>(Ops[0].getType());
170168

171-
unsigned numElts = resultType.getSize() * 8;
169+
// If pslldq is shifting the vector more than 15 bytes, emit zero.
170+
// This matches the hardware behavior where shifting by 16+ bytes
171+
// clears the entire 128-bit lane.
172172
if (shiftVal >= 16)
173173
return builder.getZero(loc, resultType);
174174

175+
// Builtin type is vXi64 so multiply by 8 to get bytes.
176+
unsigned numElts = resultType.getSize() * 8;
177+
assert(numElts % 16 == 0 && "Vector size must be multiple of 16 bytes");
178+
175179
llvm::SmallVector<int64_t, 64> indices;
176180

177-
for (unsigned l = 0; l != numElts; l += 16) {
181+
// 256/512-bit pslldq operates on 128-bit lanes so we need to handle that
182+
for (unsigned l = 0; l < numElts; l += 16) {
178183
for (unsigned i = 0; i != 16; ++i) {
179184
unsigned idx = numElts + i - shiftVal;
180185
if (idx < numElts)

0 commit comments

Comments
 (0)