[PATCH] D82398: [MSAN] Handle x86 {round,min,max}sd intrinsics

Gui Andrade via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 23 16:11:51 PDT 2020


guiand updated this revision to Diff 272855.
guiand added a comment.

Addressed comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82398/new/

https://reviews.llvm.org/D82398

Files:
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/vector_sd.ll


Index: llvm/test/Instrumentation/MemorySanitizer/vector_sd.ll
===================================================================
--- /dev/null
+++ llvm/test/Instrumentation/MemorySanitizer/vector_sd.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck  \
+; RUN: %s
+; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
+; REQUIRES: x86-registered-target
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare <2 x double> @llvm.x86.sse41.round.sd(<2 x double>, <2 x double>, i32) nounwind readnone
+declare <2 x double> @llvm.x86.sse2.min.sd(<2 x double>, <2 x double>) nounwind readnone
+
+define <2 x double> @test_sse_round_sd(<2 x double> %op1, <2 x double> %op2) sanitize_memory {
+entry:
+  ; CHECK: [[OP2_SHADOW:%[0-9]+]] = load {{.*}} @__msan_param_tls
+  ; CHECK: [[OP1_SHADOW:%[0-9]+]] = load {{.*}} @__msan_param_tls
+  ; CHECK: [[OUT_SHADOW:%.+]] = shufflevector <2 x i64> [[OP1_SHADOW]], <2 x i64> [[OP2_SHADOW]], <2 x i32> <i32 2, i32 1> 
+  ; CHECK-NOT: call void @msan_warning
+  ; CHECK: call <2 x double> @llvm.x86.sse41.round.sd
+  %0 = tail call <2 x double> @llvm.x86.sse41.round.sd(<2 x double> %op1, <2 x double> %op2, i32 0)
+  ; CHECK: store <2 x i64> [[OUT_SHADOW]], {{.*}} @__msan_retval_tls
+  ; CHECK: ret <2 x double>
+  ret <2 x double> %0
+}
+
+define <2 x double> @test_sse_min_sd(<2 x double> %op1, <2 x double> %op2) sanitize_memory {
+entry:
+  ; CHECK: [[OP2_SHADOW:%[0-9]+]] = load {{.*}} @__msan_param_tls
+  ; CHECK: [[OP1_SHADOW:%[0-9]+]] = load {{.*}} @__msan_param_tls
+  ; CHECK: [[OR_SHADOW:%.+]] = or <2 x i64> [[OP1_SHADOW]], [[OP2_SHADOW]]
+  ; CHECK: [[OUT_SHADOW_VEC:%.+]] = shufflevector <2 x i64> [[OP1_SHADOW]], <2 x i64> [[OR_SHADOW]], <2 x i32> <i32 2, i32 1> 
+  ; CHECK-NOT: call void @msan_warning
+  ; CHECK: call <2 x double> @llvm.x86.sse2.min.sd
+  %0 = tail call <2 x double> @llvm.x86.sse2.min.sd(<2 x double> %op1, <2 x double> %op2)
+  ; CHECK: store <2 x i64> [[OUT_SHADOW_VEC]], {{.*}} @__msan_retval_tls
+  ; CHECK: ret <2 x double>
+  ret <2 x double> %0
+}
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -3054,6 +3054,32 @@
     SOC.Done(&I);
   }
 
+  // Instrument _mm_*_sd intrinsics
+  void handleUnarySdIntrinsic(IntrinsicInst &I) {
+    IRBuilder<> IRB(&I);
+    Value *First = getShadow(&I, 0);
+    Value *Second = getShadow(&I, 1);
+    // High word of first operand, low word of second
+    Value *Shadow =
+        IRB.CreateShuffleVector(First, Second, llvm::makeArrayRef<int>({2, 1}));
+
+    setShadow(&I, Shadow);
+    setOriginForNaryOp(I);
+  }
+
+  void handleBinarySdIntrinsic(IntrinsicInst &I) {
+    IRBuilder<> IRB(&I);
+    Value *First = getShadow(&I, 0);
+    Value *Second = getShadow(&I, 1);
+    Value *OrShadow = IRB.CreateOr(First, Second);
+    // High word of first operand, low word of both OR'd together
+    Value *Shadow = IRB.CreateShuffleVector(First, OrShadow,
+                                            llvm::makeArrayRef<int>({2, 1}));
+
+    setShadow(&I, Shadow);
+    setOriginForNaryOp(I);
+  }
+
   void visitIntrinsicInst(IntrinsicInst &I) {
     switch (I.getIntrinsicID()) {
     case Intrinsic::lifetime_start:
@@ -3293,6 +3319,14 @@
       handlePclmulIntrinsic(I);
       break;
 
+    case Intrinsic::x86_sse41_round_sd:
+      handleUnarySdIntrinsic(I);
+      break;
+    case Intrinsic::x86_sse2_max_sd:
+    case Intrinsic::x86_sse2_min_sd:
+      handleBinarySdIntrinsic(I);
+      break;
+
     case Intrinsic::is_constant:
       // The result of llvm.is.constant() is always defined.
       setShadow(&I, getCleanShadow(&I));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82398.272855.patch
Type: text/x-patch
Size: 4002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200623/d84e7368/attachment.bin>


More information about the cfe-commits mailing list