On Fri, 2020-06-26 at 23:54 +0200, Ilya Leoshkevich wrote: > > How should this work ideally? Suppose we have: > > static inline void foo (int i) > { > if (__builtin_is_constant_p (i)) > asm volatile ("bar" :: "i" (i)) > else > asm volatile ("baz" :: "d" (i)); > } > > First of all, this is a supported use case, right? Yes, this is a supported case.
> > Then, the way I see it, is that at least for a while there must exist > trees like the ones above, regardless of whether their asm arguments > match constraints. But ultimately dead code elimination should get rid > of the wrong ones before they reach RTL. > > E.g. in the example above, the non-inlined version should have > `!__builtin_is_constant_p (i)`, so `bar` should not survive until > RTL. The same for inlined `foo (1)` version's `baz`. In theory yes, but there are cases where paths converge (like you've shown) where you may have evaluated to a constant on the paths, but it's not a constant at the convergence point. You have to be very careful using b_c_p like this and it's been a regular source of kernel bugs. I'd recommend looking at the .ssa dump and walk forward from there if the .ssa dump looks correct. jeff