Skip to content

Commit 7bd9c78

Browse files
authored
[msan][NFCI] Generalize handleIntrinsicByApplyingToShadow to allow alternative intrinsic for shadows (llvm#124831)
llvm#124159 uses handleIntrinsicByApplyingToShadow for horizontal add/sub, but Vitaly recommends always using the add version to avoid false negatives for fully uninitialized data (llvm#124662). This patch lays the groundwork by generalizing handleIntrinsicByApplyingToShadow to allow using a different intrinsic (of the same type as the original intrinsic) for the shadow. Planned work will apply it to horizontal sub.
1 parent bfefa15 commit 7bd9c78

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,7 +4049,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
40494049
// consider this an acceptable tradeoff for performance.
40504050
// To make shadow propagation precise, we want the equivalent of
40514051
// "horizontal OR", but this is not available.
4052-
return handleIntrinsicByApplyingToShadow(I, /* trailingVerbatimArgs */ 0);
4052+
return handleIntrinsicByApplyingToShadow(
4053+
I, /*shadowIntrinsicID=*/I.getIntrinsicID(),
4054+
/*trailingVerbatimArgs*/ 0);
40534055
}
40544056

40554057
/// Handle Arm NEON vector store intrinsics (vst{2,3,4}, vst1x_{2,3,4},
@@ -4156,6 +4158,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
41564158
/// shadow[out] =
41574159
/// intrinsic(shadow[var1], shadow[var2], opType) | shadow[opType]
41584160
///
4161+
/// Typically, shadowIntrinsicID will be specified by the caller to be
4162+
/// I.getIntrinsicID(), but the caller can choose to replace it with another
4163+
/// intrinsic of the same type.
4164+
///
41594165
/// CAUTION: this assumes that the intrinsic will handle arbitrary
41604166
/// bit-patterns (for example, if the intrinsic accepts floats for
41614167
/// var1, we require that it doesn't care if inputs are NaNs).
@@ -4165,6 +4171,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
41654171
///
41664172
/// The origin is approximated using setOriginForNaryOp.
41674173
void handleIntrinsicByApplyingToShadow(IntrinsicInst &I,
4174+
Intrinsic::ID shadowIntrinsicID,
41684175
unsigned int trailingVerbatimArgs) {
41694176
IRBuilder<> IRB(&I);
41704177

@@ -4188,7 +4195,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
41884195
}
41894196

41904197
CallInst *CI =
4191-
IRB.CreateIntrinsic(I.getType(), I.getIntrinsicID(), ShadowArgs);
4198+
IRB.CreateIntrinsic(I.getType(), shadowIntrinsicID, ShadowArgs);
41924199
Value *CombinedShadow = CI;
41934200

41944201
// Combine the computed shadow with the shadow of trailing args
@@ -4664,7 +4671,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
46644671
case Intrinsic::aarch64_neon_tbx3:
46654672
case Intrinsic::aarch64_neon_tbx4: {
46664673
// The last trailing argument (index register) should be handled verbatim
4667-
handleIntrinsicByApplyingToShadow(I, 1);
4674+
handleIntrinsicByApplyingToShadow(
4675+
I, /*shadowIntrinsicID=*/I.getIntrinsicID(),
4676+
/*trailingVerbatimArgs*/ 1);
46684677
break;
46694678
}
46704679

0 commit comments

Comments
 (0)