From d421223e2538b5193d2399a324d746dc18525cda Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 14 Sep 2022 18:18:45 -0700 Subject: [PATCH] [msan] Resolve FIXME from D133880 We don't need to change tests we convertToBool unconditionally only before OR. --- .../Transforms/Instrumentation/MemorySanitizer.cpp | 21 +++++++++------------ .../MemorySanitizer/with-call-type-size.ll | 11 +++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index f75d5a1..7fb6e7f 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1369,9 +1369,7 @@ struct MemorySanitizerVisitor : public InstVisitor { assert(ShadowData.OrigIns == Instruction); IRBuilder<> IRB(Instruction); - LLVM_DEBUG(dbgs() << " SHAD0 : " << *ShadowData.Shadow << "\n"); - Value *ConvertedShadow = convertShadowToScalar(ShadowData.Shadow, IRB); - LLVM_DEBUG(dbgs() << " SHAD1 : " << *ConvertedShadow << "\n"); + Value *ConvertedShadow = ShadowData.Shadow; if (auto *ConstantShadow = dyn_cast(ConvertedShadow)) { if (!ClCheckConstantShadow || ConstantShadow->isZeroValue()) { @@ -1389,21 +1387,19 @@ struct MemorySanitizerVisitor : public InstVisitor { // Fallback to runtime check, which still can be optimized out later. } - // Work around to keep existing tests. - // FIXME: update tests and remove. - if (ClInstrumentationWithCallThreshold >= 0 && - SplittableBlocksCount >= ClInstrumentationWithCallThreshold) { + if (!Combine) { materializeOneCheck(IRB, ConvertedShadow, ShadowData.Origin); continue; } - if (!Combine) { - materializeOneCheck(IRB, ConvertedShadow, ShadowData.Origin); + if (!Shadow) { + Shadow = ConvertedShadow; continue; } - Value *BoolShadow = convertToBool(ConvertedShadow, IRB, "_mscmp"); - Shadow = Shadow ? IRB.CreateOr(Shadow, BoolShadow, "_msor") : BoolShadow; + Shadow = convertToBool(Shadow, IRB, "_mscmp"); + ConvertedShadow = convertToBool(ConvertedShadow, IRB, "_mscmp"); + Shadow = IRB.CreateOr(Shadow, ConvertedShadow, "_msor"); } if (Shadow) { @@ -1600,7 +1596,8 @@ struct MemorySanitizerVisitor : public InstVisitor { // Convert a scalar value to an i1 by comparing with 0 Value *convertToBool(Value *V, IRBuilder<> &IRB, const Twine &name = "") { Type *VTy = V->getType(); - assert(VTy->isIntegerTy()); + if (!VTy->isIntegerTy()) + return convertToBool(convertShadowToScalar(V, IRB), IRB, name); if (VTy->getIntegerBitWidth() == 1) // Just converting a bool to a bool, so do nothing. return V; diff --git a/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll b/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll index e39c5d2c..bec6fe4 100644 --- a/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll @@ -89,3 +89,14 @@ define <4 x i32> @testUndef(<4 x i32> %vec, i32 %x) sanitize_memory { ; CHECK-LABEL: @testUndef( ; CHECK: call void @__msan_warning_noreturn ; CHECK: ret <4 x i32> + +declare <256 x i16> @llvm.masked.load.v256i16.p0v256i16(<256 x i16>*, i32, <256 x i1>, <256 x i16>) +define <256 x i16> @testCombine(<256 x i16>* %vec, <256 x i1> %mask) sanitize_memory { + %vec1 = call <256 x i16> @llvm.masked.load.v256i16.p0v256i16(<256 x i16>* %vec, i32 16, <256 x i1> %mask, <256 x i16> zeroinitializer) + ret <256 x i16> %vec1 +} +; CHECK-LABEL: @testCombine( +; CHECK: %[[A:.*]] = or i1 %{{.*}}, %{{.*}} +; CHECK: %[[B:.*]] = zext i1 %[[A]] to i8 +; CHECK: call void @__msan_maybe_warning_1(i8 zeroext %[[B]], i32 zeroext 0) +; CHECK: ret <256 x i16> -- 2.7.4