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

    <tr>
        <th>Summary</th>
        <td>
            Seemingly well defined program is optimized away as undefined
        </td>
    </tr>

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

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

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

<pre>
    This (reduced csmith) program should always print '1':

```
int printf(const char *, ...);
long a, e;
short b;
int d;
int main() {
  int f[2];
  for (b = 0; b <= 3; b++)
    ;
  int *g = &f[1];
  d = *g;
  e = d == 0 ? e : a / d;
  printf("%d\n", 1);
}
```
Even though f is uninitialized, the address of f[1] is taken, which means it will not be 'register', and not automatically disqualify the whole program as undefined, IIUC. 'd' holds the value of f[1], which is unspecified, but however checked against 0 before dividing. 'e' will always be 0 regardless of 'd', since both 'a' and 'e' are 0.

The result is however that the whole program is optimized away and the call to printf is never made.

I see:

```
*** IR Dump After EarlyCSEPass on main ***
...
  br i1 undef, label %cond.true, label %cond.false

cond.true:                                        ; preds = %for.end
  %1 = load i64, ptr @e, align 8, !tbaa !12
  br label %cond.end

cond.false:                                       ; preds = %for.end
  %2 = load i64, ptr @a, align 8, !tbaa !12
  br label %cond.end

cond.end:                                         ; preds = %cond.false, %cond.true
  %cond = phi i64 [ %1, %cond.true ], [ poison, %cond.false ]
  store i64 %cond, ptr @e, align 8, !tbaa !12
  %call = call signext i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef signext 1)
  ret i32 0
}
```

It is true that the branch is undefined in a way at this point, but regardless of which branch target is chosen, the result is the same and printf will be called. I wonder if it is really correct to optimize away the printf call in this case...?

@uweigand @efriedma-quic 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVttu4zgPfhrlhhjDVuIcLnLRJhOg_9Xgn9kHkC3a5o4sZSS52ezTLy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