[llvm] d421223 - [msan] Resolve FIXME from D133880

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 14 18:56:28 PDT 2022


Author: Vitaly Buka
Date: 2022-09-14T18:55:57-07:00
New Revision: d421223e2538b5193d2399a324d746dc18525cda

URL: https://github.com/llvm/llvm-project/commit/d421223e2538b5193d2399a324d746dc18525cda
DIFF: https://github.com/llvm/llvm-project/commit/d421223e2538b5193d2399a324d746dc18525cda.diff

LOG: [msan] Resolve FIXME from D133880

We don't need to change tests we convertToBool
unconditionally only before OR.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
    llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index f75d5a1a2a09..7fb6e7f1c1a4 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1369,9 +1369,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
       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<Constant>(ConvertedShadow)) {
         if (!ClCheckConstantShadow || ConstantShadow->isZeroValue()) {
@@ -1389,21 +1387,19 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
         // 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<MemorySanitizerVisitor> {
   // 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 e39c5d2cddbd..bec6fe40bd93 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>


        


More information about the llvm-commits mailing list