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

    <tr>
        <th>Summary</th>
        <td>
            [SCEV] SCEV drops NSW for add 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    I have the following code where SCEV drops `nsw` for the instruction `%add`. What am I missing? Is this intended or a bug?
```llvm
define void @foo(ptr %a, i32 noundef %i) local_unnamed_addr {
entry:
  br i1 true, label %if_true, label %if_false
if_true:
  %add = add nsw i32 %i, 1
  %idxprom3 = sext i32 %add to i64
  %arrayidx4 = getelementptr inbounds i32, ptr %a, i64 %idxprom3
  %i2 = load i32, ptr %arrayidx4, align 4
  ret void
if_false:
  ret void
}
```
If I run `opt -passes=print<scalar-evolution>`, ([to reproduce](https://godbolt.org/z/Gezve8Gjo)), I get `(1 + %i)` instead of `(1 + %i)<nsw>`.

I get the desired  `nsw` flag if I remove the branches instead ([to reproduce](https://godbolt.org/z/q67fEvYG4)).
```llvm
; Function Attrs: argmemonly mustprogress nofree norecurse nosync nounwind ssp willreturn uwtable
define void @foo(ptr %a, i32 noundef %i) local_unnamed_addr {
entry:
;  br i1 true, label %if_true, label %if_false
;if_true:
  %add = add nsw i32 %i, 1
  %idxprom3 = sext i32 %add to i64
  %arrayidx4 = getelementptr inbounds i32, ptr %a, i64 %idxprom3
  %i2 = load i32, ptr %arrayidx4, align 4
  ret void
;if_false:
;  ret void
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVclu2zAQ_Rr6Mogha7UPOsTOglx6CdCgp4ASRxYDinRJyo7z9R1SdeIEKQrk0EsB2RLJmTcL3yMbI471HfR8j-B7hM4oZQ5Sb6E1AuHQo0W431x_B2HNzgErE-0O9E-WNnpI7bwdWy-NDqssLbgQ9DGHh5574APcwSCdI0yW3cCdIy_pyM2jFiiAYDg0Y1hkyRVLLgNIfJTaD9OUwE5qhL2RAliedMawdLnzFkI0lm5AZiloMxJgF-YkS1egTMvV46g1H1A8UlJkXq0nQNTeHll2OY0AGgtyAVQHBjTFG1QRp3v8bK7jyuHkerJ4g5oaACy7gvCmbsXspqw2sDizk-J5Z82QRWOHz_5kGRy9AVnm56jW8iO55NF8ix4VDlRI6IPUTajeBYAQ5V1vyvw82Hn8NEIpw8VHx1OsMMeV3Gp4TcWijzvx2oCpHW8deG_AqqsP-zoN7zoihh0jaczOw8WOO4eOEtpZIgfLNo72j9sL3Bs1Bnqx7DoSbEMZLlmxpg5ZpJrE2CIrrmiy937nQibpDT1bIxqj_NzYLY1e6HeLL3tc3j4RfVbx2VAO1MmJuMsFAa9P_AkcD9xGao7pPrXINkELMav57xqn0iJmEIdAJy2R_Fw3im9BxuJxML9l11iu2x7da8SvVvizrLrr_Y_bfKpw_kdJsWwNN6OedHvpvQ2owO12oKy0OsIwOk-htxadI211FpFeFtvRuvDljrqNmqPTQoBzOzhIpWjvR6thPHjeKPwn6g2VfF3A5P3fa3jqwXsZx67-TckzUWdila34zEuvsCbKhruCqHp-Z3y7f4i3RejIbLSq_kBi6fuxmbdmoEEk6PS6oFKfsPU0pOtjpKMhvSnKYlXO-jorkqTEtmhavkrbrihXXYVJ0eZ5wzHNm1ncbRcSomRmsk6TNE2qxXKxzJO8mlepWLQVlhm5VlnOiZY4cKnmIXCQ08zWMQe6mBwtKum8e1ukk4raiXjC56Pvja2PJGGdJeUs5lvHZH8BVPM2IQ">