On 7/14/25 09:41, Pierrick Bouvier wrote:
Indeed, clang does not fold the condition "value && kvm_enabled() && !
kvm_arm_sve_supported()". Looks like a missing case.
This code compiles with gcc -O0, but not clang -O0.
extern int f(void);
int main(int argc) {
if (argc && 0)
f();
}
As folding is not guaranteed by C standard, I'm not sure it's really possible to file a
bug. However, since we rely on this behaviour in other parts, maybe it would be better to
rewrite the condition on our side.
It's probably worth filing a missed-optimization type bug, if that's available in clang's
reporting system.
With my compiler hat on, I suspect that GCC generates IR like
if (argc) {
if (0) {
f();
}
}
in order to get the short-circuting part of && correct, which Just So Happens to fold away
exactly as we wish.
I'm not sure how clang expands the expression such that (x && 0) doesn't fold away, but (0
&& x) does, as evidenced by
+ if (kvm_enabled() && !kvm_arm_sve_supported()) {
r~