[llvm] [DSE] Handle provenance when eliminating tautological assignments (PR #184311)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 04:08:23 PST 2026


================
@@ -2275,6 +2276,12 @@ bool DSEState::dominatingConditionImpliesValue(MemoryDef *Def) {
       !ICmpInst::isEquality(Pred))
     return false;
 
+  // Ensure the replacement is allowed when comparing pointers, as
+  // the equality compares addresses only, not pointers' provenance.
+  if (StoreVal->getType()->isPointerTy() &&
+      !canReplacePointersIfEqual(ICmpL, StoreVal, DL))
----------------
nikic wrote:

Strictly speaking, this should be

```suggestion
      !canReplacePointersIfEqual(StoreVal, ICmpL, DL))
```
If we drop the store of StoreVal, we'll use the loaded value (ICmpL) instead.

I think it would make sense to use the correct order here, and fix canReplacePointersIfEqual() to support the null replacement in that case. What canReplacePointersIfEqual() currently allows (replacing %p with null) is actually something that's illegal but permitted for pragmatic purposes. But the replacement of null with %p is valid.

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


More information about the llvm-commits mailing list