[llvm] [msan] Add debugging for handleUnknownIntrinsic (PR #123381)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 10:00:52 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Thurston Dang (thurstond)
<details>
<summary>Changes</summary>
This adds an experimental flag, msan-dump-strict-intrinsics (modeled after msan-dump-strict-instructions), which prints out any intrinsics that are heuristically handled. Additionally, MSan will print out heuristically handled intrinsics when -debug is passed as a flag in debug builds.
MSan's intrinsic handling can be broken down into:
1) special cases (usually highly accurate)
2) heuristic handling (sometimes erroneous)
3) not handled
This patch's -msan-dump-strict-intrinsics is intended to help debug Case 2. Case 3) (which includes all the heuristics that are not handled by special cases nor heuristics) can be debugged using the existing -msan-dump-strict-instructions.
---
Full diff: https://github.com/llvm/llvm-project/pull/123381.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+23-13)
``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 429e323b6b7c24..1564f4c9ebd428 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -318,6 +318,13 @@ static cl::opt<bool> ClDumpStrictInstructions(
cl::desc("print out instructions with default strict semantics"),
cl::Hidden, cl::init(false));
+static cl::opt<bool> ClDumpStrictIntrinsics(
+ "msan-dump-strict-intrinsics",
+ cl::desc("Prints 'unknown' intrinsics that were handled heuristically. "
+ "Use -msan-dump-strict-instructions to print intrinsics that "
+ "could not be handled exactly nor heuristically."),
+ cl::Hidden, cl::init(false));
+
static cl::opt<int> ClInstrumentationWithCallThreshold(
"msan-instrumentation-with-call-threshold",
cl::desc(
@@ -3016,28 +3023,29 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
/// handling as an example of that.
bool handleUnknownIntrinsic(IntrinsicInst &I) {
unsigned NumArgOperands = I.arg_size();
- if (NumArgOperands == 0)
- return false;
- if (NumArgOperands == 2 && I.getArgOperand(0)->getType()->isPointerTy() &&
+ bool success = false;
+ if (NumArgOperands == 0) {
+ // No-op
+ } else if (NumArgOperands == 2 && I.getArgOperand(0)->getType()->isPointerTy() &&
I.getArgOperand(1)->getType()->isVectorTy() &&
I.getType()->isVoidTy() && !I.onlyReadsMemory()) {
// This looks like a vector store.
- return handleVectorStoreIntrinsic(I);
- }
-
- if (NumArgOperands == 1 && I.getArgOperand(0)->getType()->isPointerTy() &&
+ success = handleVectorStoreIntrinsic(I);
+ } else if (NumArgOperands == 1 && I.getArgOperand(0)->getType()->isPointerTy() &&
I.getType()->isVectorTy() && I.onlyReadsMemory()) {
// This looks like a vector load.
- return handleVectorLoadIntrinsic(I);
- }
+ success = handleVectorLoadIntrinsic(I);
+ } else if (I.doesNotAccessMemory())
+ success = maybeHandleSimpleNomemIntrinsic(I);
+
+ if (success && ClDumpStrictIntrinsics)
+ dumpInst(I);
- if (I.doesNotAccessMemory())
- if (maybeHandleSimpleNomemIntrinsic(I))
- return true;
+ LLVM_DEBUG(dbgs() << "UNKNOWN INTRINSIC HANDLED HEURISTICALLY: " << I << "\n");
// FIXME: detect and handle SSE maskstore/maskload
- return false;
+ return success;
}
void handleInvariantGroup(IntrinsicInst &I) {
@@ -4033,6 +4041,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
void visitIntrinsicInst(IntrinsicInst &I) {
switch (I.getIntrinsicID()) {
+#if 0
case Intrinsic::uadd_with_overflow:
case Intrinsic::sadd_with_overflow:
case Intrinsic::usub_with_overflow:
@@ -4445,6 +4454,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
handleNEONVectorMultiplyIntrinsic(I);
break;
}
+#endif
default:
if (!handleUnknownIntrinsic(I))
``````````
</details>
https://github.com/llvm/llvm-project/pull/123381
More information about the llvm-commits
mailing list