[llvm] [Utils][Local] Preserve !nosanitize in combineMetadata when merging instructions (PR #148376)

Kunqiu Chen via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 12 08:19:30 PDT 2025


================
@@ -409,6 +409,31 @@ join:
   ret void
 }
 
+define void @test_nosanitize(ptr %p) {
+; CHECK-LABEL: define void @test_nosanitize
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[V1:%.*]] = load i32, ptr [[P]], align 4, !nosanitize [[META6]]
+; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[V1]], 0
+; CHECK-NEXT:    br i1 [[COND]], label [[IF:%.*]], label [[JOIN:%.*]]
+; CHECK:       if:
+; CHECK-NEXT:    call void @use.i32(i32 0)
+; CHECK-NEXT:    br label [[JOIN]]
+; CHECK:       join:
+; CHECK-NEXT:    ret void
+;
+  %v1 = load i32, ptr %p, !nosanitize !11
+  %cond = icmp eq i32 %v1, 0
+  br i1 %cond, label %if, label %join
+
+if:
+  %v2 = load i32, ptr %p, !nosanitize !11
+  call void @use.i32(i32 %v2)
+  br label %join
+
+join:
+  ret void
+}
----------------
Camsyn wrote:

Imagine such a situation where
1. a third-party tool instrumentation a `nosanitize` instruction; 
2. just after that, there is the same user instruction without `nosanitize`, and 
3. GVN will delete and replace the second user instruction with the first one.

So in this scenario, I think the `nosanitize` of the first instruction should be dropped even if `!DoesKMove` is used to allow the sanitizer to sanitize the user code semantics.

Therefore, I only preserve the `nosanitize` if both instructions have it.

https://github.com/llvm/llvm-project/pull/148376


More information about the llvm-commits mailing list