[llvm] [DSE] Handle provenance when eliminating tautological assignments (PR #184311)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 00:54:38 PST 2026
================
@@ -1179,3 +1181,56 @@ if.else:
end:
ret void
}
+
+; Should not optimize as `*x` and `y` ptrs may have different provenance.
+define void @remove_tautological_store_of_ptr(ptr %x, ptr %y) {
+; CHECK-LABEL: @remove_tautological_store_of_ptr(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[VAL:%.*]] = load ptr, ptr [[X:%.*]], align 8
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[VAL]], [[Y:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[END:%.*]]
+; CHECK: then:
+; CHECK-NEXT: store ptr [[Y]], ptr [[X]], align 8
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: ret void
+;
+entry:
+ %val = load ptr, ptr %x, align 8
+ %cmp = icmp eq ptr %val, %y
+ br i1 %cmp, label %then, label %end
+
+then:
+ store ptr %y, ptr %x, align 8
+ br label %end
+
+end:
+ ret void
+}
+
+; Dominating equality `*x == null` holds, the store would introduce nullary
+; provenance. Going from non-nullary provenance to nullary provenance does
+; maintain provenance monotonicity.
----------------
nikic wrote:
```suggestion
; provenance. Thanks to provenance monotonicity, we are allowed to replace a
; pointer with nullary provenance with one with potentially non-nullary provenance.
```
https://github.com/llvm/llvm-project/pull/184311
More information about the llvm-commits
mailing list