On 14/7/25 17:52, Richard Henderson wrote:
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()) {
I'd prefer move the kvm_enabled() call instead of re-introducing the stubs:
-- >8 --
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 26cf7e6dfa2..37c7cc7b18e 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -318,9 +318,11 @@ static void cpu_arm_set_sve(Object *obj, bool
value, Error **errp)
{
ARMCPU *cpu = ARM_CPU(obj);
- if (value && kvm_enabled() && !kvm_arm_sve_supported()) {
- error_setg(errp, "'sve' feature not supported by KVM on this
host");
- return;
+ if (kvm_enabled()) {
+ if (value && !kvm_arm_sve_supported()) {
+ error_setg(errp, "'sve' feature not supported by KVM on
this host");
+ return;
+ }
}
FIELD_DP64_IDREG(&cpu->isar, ID_AA64PFR0, SVE, value);
---