<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78271>78271</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[missed optimization] AND-operation shortcut not taken; potential unnecessary load
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
colin-arnet
</td>
</tr>
</table>
<pre>
In foo0 both variables are compared to 0 and then put into the and-operation.
gcc takes a shortcut if the first variable is 0 (entire statement is 0).
llvm takes the shortcut when both variables are local or the order of the variables in the statement is switched. (foo1, foo2)
https://godbolt.org/z/voE9Gfdhv
```C
int g;
int foo0(int *b) {
return *b && g;
}
int foo1(int *b, int *c) {
return *b && *c;
}
int foo2(int *b){
return g && *b;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEk8-O2jAQxp9mchmBnAmQ5JADu5Sql76DkzjErfEge8Jq9-krBxbYFqlS5PjPzM-f7fl0jPbgjWlg_QLrXaYnGTk0HTvrFzp4I1nL_Xvzw-PArLBlGfGsg9WtMxF1MNjx8aSD6VEYFWrfo4zG42kStF44jdLsgk8maLHslwhqB2p76DoU_TthMI4cpEspw5ww2BDlthHaiAqBKuPFBoNRtJij8TIvANWfSOfOxyszUW7Ut6ToiXbHnXbIYY7m0JuAfBFwj7P-wnrcM75Z6UbTL5OogTkHek0XRED1RcmlHUVOEYot0B5of-C-ZSdLDgeg_QfQ_szf6u9DP56vSRt1-V4vY-sFD1C8PCLTXHoKoCp1gbYtUI1QXqMQg5Ep-HkFgTZAm38gUO6eMPMvzFe89rv_8-eo2xZP4fRV8APvRjw84NonuM_b-XKSuc36pujrotaZafJSrVe5Kus8G5s6b4t1VVX5oGtlSjVoGtrC6Naosl8VlNmGFK1Unm_yIi_yfNlTVdeFKtdD23ZVsYKVMkdt3TLVVnq6zMY4maasqMwzp1vj4uweIm_ecF4EomSm0KScRTsdIqyUs1HinSJW3Gy7o43R9MgnsUf7MTsE1jvc_tzdLXOvZM8yF7iH4gVPLMkR2uHkvelMjDq8o2PdZ1NwzV_VZ2Wc2mXHR6B9knH9LU6Bf5lOgPaz-Ai0nw_3JwAA__8pZT-R">