Skip to content

Commit 9b32b57

Browse files
committed
Press F to pay respects to Florian's feedback
1 parent 89d6f6c commit 9b32b57

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,13 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
43124312
setOriginForNaryOp(I);
43134313
}
43144314

4315+
Value *extractLowerShadow(IRBuilder<> &IRB, Value *V) {
4316+
assert(isa<FixedVectorType>(V->getType()));
4317+
assert(cast<FixedVectorType>(V->getType())->getNumElements() > 0);
4318+
Value *Shadow = getShadow(V);
4319+
return IRB.CreateExtractElement(Shadow, ConstantInt::get(IRB.getInt32Ty(), 0));
4320+
}
4321+
43154322
// For sh.* compiler intrinsics:
43164323
// llvm.x86.avx512fp16.mask.{add/sub/mul/div/max/min}.sh.round
43174324
// (<8 x half>, <8 x half>, <8 x half>, i8, i32)
@@ -4329,7 +4336,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
43294336
Value *Mask = I.getOperand(3);
43304337
Value *RoundingMode = I.getOperand(4);
43314338

4332-
// Technically, we could probably just check whether the LSB is initialized
4339+
// Technically, we could probably just check whether the LSB is
4340+
// initialized, but intuitively it feels like a partly uninitialized mask
4341+
// is unintended, and we should warn the user immediately.
43334342
insertShadowCheck(Mask, &I);
43344343
insertShadowCheck(RoundingMode, &I);
43354344

@@ -4342,25 +4351,19 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
43424351
assert(Mask->getType()->getPrimitiveSizeInBits() == NumElements);
43434352
assert(RoundingMode->getType()->isIntegerTy());
43444353

4345-
Value *AShadow = getShadow(A);
4346-
Value *AShadowLower = IRB.CreateExtractElement(
4347-
AShadow, ConstantInt::get(IRB.getInt32Ty(), 0));
4348-
4349-
Value *BShadow = getShadow(B);
4350-
Value *BShadowLower = IRB.CreateExtractElement(
4351-
BShadow, ConstantInt::get(IRB.getInt32Ty(), 0));
4354+
Value *ALowerShadow = extractLowerShadow(IRB, A);
4355+
Value *BLowerShadow = extractLowerShadow(IRB, B);
43524356

4353-
Value *ABLowerShadow = IRB.CreateOr(AShadowLower, BShadowLower);
4357+
Value *ABLowerShadow = IRB.CreateOr(ALowerShadow, BLowerShadow);
43544358

4355-
Value *WriteThroughShadow = getShadow(WriteThrough);
4356-
Value *WriteThroughLowerShadow = IRB.CreateExtractElement(
4357-
WriteThroughShadow, ConstantInt::get(IRB.getInt32Ty(), 0));
4359+
Value *WriteThroughLowerShadow = extractLowerShadow(IRB, WriteThrough);
43584360

43594361
Mask = IRB.CreateBitCast(
43604362
Mask, FixedVectorType::get(IRB.getInt1Ty(), NumElements));
43614363
Value *MaskLower =
43624364
IRB.CreateExtractElement(Mask, ConstantInt::get(IRB.getInt32Ty(), 0));
43634365

4366+
Value *AShadow = getShadow(A);
43644367
Value *DstLowerShadow =
43654368
IRB.CreateSelect(MaskLower, ABLowerShadow, WriteThroughLowerShadow);
43664369
Value *DstShadow = IRB.CreateInsertElement(

0 commit comments

Comments
 (0)