On on Fri, 16 Oct 2026 10:43:22 +0200, Jakub Jelinek <[email protected]> wrote: > On Thu, Oct 15, 2026 at 06:00:03PM +0530, [email protected] wrote: >> gcc/ChangeLog: >> >> * Makefile.in: Add atomic-ifn-lowering.o. >> * atomic-ifn-lowering.cc: New file. >> * atomic-ifn-lowering.h: New file. >> * doc/extend.texi: Document __atomic_fetch_min and >> __atomic_fetch_max. >> * gimple-isel.cc: Include atomic-ifn-lowering.h. >> (pass_gimple_isel::execute): Invoke atomic IFN lowering. >> * internal-fn.cc (expand_ATOMIC_FETCH_MINMAX): Add placeholder. >> * internal-fn.def (ATOMIC_FETCH_MINMAX): New internal function. >> * sync-builtins.def (BUILT_IN_ATOMIC_FETCH_MIN): New builtin. >> (BUILT_IN_ATOMIC_FETCH_MAX): Likewise. >> >> gcc/c-family/ChangeLog: >> >> * c-common.cc (atomic_bitint_fetch_using_cas_loop): Handle >> atomic fetch min/max. >> (resolve_overloaded_builtin): Resolve atomic min/max builtins to >> IFN_ATOMIC_FETCH_MINMAX. >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/eh/atomic-fetch-minmax-nce.C: New test. >> * g++.dg/eh/atomic-fetch-minmax-no-nce.C: New test. >> * g++.dg/template/builtin-atomic-overloads6.C: Extend for fetch >> min/max. >> * g++.dg/template/builtin-atomic-overloads7.C: Likewise. >> * gcc.dg/atomic-fetch-minmax-bad-types.c: New test. >> * gcc.dg/atomic-fetch-minmax-bitint.c: New test. >> * gcc.dg/atomic-fetch-minmax-ifn.c: New test. >> * gcc.dg/atomic-fetch-minmax-lower.c: New test. >> * gcc.dg/atomic-fetch-minmax-pointers.c: New test. >> * gcc.dg/atomic-fetch-minmax-sign-cast.c: New test. >> * gcc.dg/atomic-fetch-minmax-type-mismatch.c: New test. >> * gcc.dg/atomic-op-1.c: Extend for fetch min/max. >> * gcc.dg/atomic-op-2.c: Likewise. >> * gcc.dg/atomic-op-3.c: Likewise. >> * gcc.dg/atomic-op-4.c: Likewise. >> * gcc.dg/atomic-op-5.c: Likewise. >> >> Signed-off-by: Soumya AR <[email protected]> > > Like this it is an unconditional extra walk of the whole IL, for something > that won't appear in 99.99% of functions. > > Why don't you just call maybe_lower_atomic_ifn from the > pass_gimple_isel::execute walk over IL? Or at least note if such ifn calls > are present and do the extra walk of the whole IL only if such insns are > present?
That makes sense, I've gone with the second approach for now. Similar to the older version of this patch, we now save the calls we encounter to lower them afterwards. gimple-isel keeps ranger enabled for the IL walk, so manipulating the CFG by lowering in place might mess with that (although I haven't tested this myself). I can change this to lower in-place if that’s better. Also, I'd messed up the rebase for these patches and accidentally put can_expand_atomic_fetch_minmax_p in the first patch. I've moved it back to the expand patch in this version. Sorry for the confusion. Best, Soumya > > Jakub
v5-0001-middle-end-Add-support-for-atomic-fetch-min-max-b.patch
Description: v5-0001-middle-end-Add-support-for-atomic-fetch-min-max-b.patch
v5-0002-expand-Expand-IFN_ATOMIC_FETCH_MINMAX-to-target-s.patch
Description: v5-0002-expand-Expand-IFN_ATOMIC_FETCH_MINMAX-to-target-s.patch
