On Mon, Nov 07, 2022 at 10:31:21AM +0000, Richard Biener wrote: > On Mon, 7 Nov 2022, Jakub Jelinek wrote: > > > On Mon, Nov 07, 2022 at 10:02:11AM +0100, Richard Biener wrote: > > > The following adds a fold_builtins pass at -O0, keying off some > > > unwanted optimization and setting pointer alignment of the result > > > of __builtin_assume_alignment before removing the call. This > > > allows libatomic calls to be elided at -O0 on s390 for > > > > > > __uint128_t foo(__uint128_t *p) > > > { > > > return __atomic_load_n((__uint128_t *)__builtin_assume_aligned (p, 16), > > > 0); > > > } > > > > > > not sure how to reliably test this though. > > > > > > Thoughts? > > > > Do we really need a separate pass for it? > > Can't we do it say during gimplification? > > gimplification would be too early for always inline - of course since > we don't do any copy propagation the source pattern this works reliably > are limited, mostly when used directly as arguments like in the example > above.
Yeah, that was exactly my thinking, because we don't copy propagate at -O0, it will only handle cases where there is exactly one SSA_NAME involved. The advantage of doing it at gimplification time is that we don't need to add an extra pass for -O0. > So yes, the specific case in question would work when we elide > __builtin_assume_aligned during gimplification at -O0 (or during > the GIMPLE lower pass). > > Would you prefer that? Richard, would that work for you? Jakub