https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100798
Bug ID: 100798
Summary: a?~t:t and (-(!!a))^t don't produce the same assembly
code
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
While working on non GCC code, I notice these two functions don't produce the
assembly code:
int f(int a, int t)
{
return (a=='s' ? ~t : t);
}
int f1(int a, int t)
{
int t1 = -(a=='s');
return (t1 ^ t);
}
For aarch64, the first case produce the best, while on x86_64, I don't know
which is better, sete or cmov.
Note LLVM produces the same code for both, for aarch64, the csinv and
sete/neg/xor for x86_64.