https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112962
--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to Jakub Jelinek from comment #3) > I was thinking whether it wouldn't be better to expand x86 const or pure > builtins when lhs is ignored to nothing in the expanders. Something like this? --cut here-- diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index a53d69d5400..0f3d6108d77 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -13032,6 +13032,9 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget, unsigned int fcode = DECL_MD_FUNCTION_CODE (fndecl); HOST_WIDE_INT bisa, bisa2; + if (ignore && (TREE_READONLY (fndecl) || DECL_PURE_P (fndecl))) + return const0_rtx; + /* For CPU builtins that can be folded, fold first and expand the fold. */ switch (fcode) { @@ -14401,9 +14404,6 @@ rdseed_step: return target; case IX86_BUILTIN_READ_FLAGS: - if (ignore) - return const0_rtx; - emit_insn (gen_pushfl ()); if (optimize --cut here--