<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/133621>133621</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            is EarlyCSEPass folding icmp of global to null => false correct?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          workingjubilee
      </td>
    </tr>
</table>

<pre>
    We recently discovered that EarlyCSEPass applies something like the following transformation:
```diff
@GLIBC_PRIVATE = external global {}

define noundef zeroext i1 @example_foo_h402e223ff693409d() unnamed_addr {
start:
-  %_0 = icmp eq i64 ptrtoint (ptr @GLIBC_PRIVATE to i64), 0
-  ret i1 %_0
+  ret i1 false
}
```

Unfortunately, this symbol is actually "linked" at 0x0.

The full(?) LLVMIR with no prepopulated passes, though the externally linked item declaration seems to have gone missing...? It should be as above
```llvm
source_filename = "example.22da6be311ca0e3f-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define noundef zeroext i1 @_ZN7example3foo17h402e223ff693409dE() unnamed_addr #0 {
  %_0 = icmp eq i64 ptrtoint (ptr @GLIBC_PRIVATE to i64), 0
  ret i1 %_0
}

attributes #0 = { noinline nonlazybind uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"RtLibUseGOT", i32 1}
!2 = !{!"rustc version 1.85.0 (4d91de4e4 2025-02-17)"}
```

As an external global of zero bytes can seemingly be given the address of 0x0 without needing to be initialized, and doing so might make sense, it seems that this folding is incorrect. Or, at least, the LangRef needs a considerable amount of updating to explain this optimization's justification.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJys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