https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128662

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <[email protected]>:

https://gcc.gnu.org/g:01f482bf9819d591c6d1cdbecef2fa30512b8ab4

commit r17-6465-g01f482bf9819d591c6d1cdbecef2fa30512b8ab4
Author: Uros Bizjak <[email protected]>
Date:   Thu Nov 19 10:34:48 2026 +0100

    i386: Avoid false dependency for BSF [PR128662]

    BSF, like BSR, leaves its destination unmodified when the source is
    zero, so the hardware treats the destination as an input.  The new
    X86_TUNE_AVOID_FALSE_DEP_FOR_BSR tuning already clears the destination
    before BSR, but BSF was not handled:

     - *bsf<mode>_1 (used by the ffs expansion) was never split.
     - The ctz splitters were restricted to TARGET_BMI or generic tuning,
       so a non-generic tuning without TZCNT, which prints plain bsf, never
       got the clear.

    Use TARGET_AVOID_FALSE_DEP_FOR_BSR for the BSF forms when TARGET_BMI is
    not set, and keep the BMI and TZCNT tunings for the tzcnt form.  The
    falsedep insns can now be reached with plain bsf, so print it instead
    of hitting gcc_unreachable.  Generic tuning without BMI is unchanged,
    since it is in both tuning masks.

    Assisted-by: Claude Sonnet 5.5

            PR target/128662

    gcc/ChangeLog:

            * config/i386/i386.md (*bsf<mode>_1): Convert to
            define_insn_and_split.  Split to *bsf<mode>_1_falsedep when
            TARGET_AVOID_FALSE_DEP_FOR_BSR is set and the destination is not
            mentioned in the source.
            (*bsf<mode>_1_falsedep): New insn.
            (ctz<mode>2): Use TARGET_AVOID_FALSE_DEP_FOR_BSR in the split
            condition when TARGET_BMI is not set.
            (*ctzsidi2_<s>ext): Ditto.
            (*ctz<mode>2_falsedep): Output plain bsf instead of
            gcc_unreachable.  Update prefix_rep attribute.
            (*ctzsidi2_<s>ext_falsedep): Ditto.
            * config/i386/x86-tune.def (X86_TUNE_AVOID_FALSE_DEP_FOR_BSR):
            Update comment.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr128662.c: Rename to...
            * gcc.target/i386/pr128662-1.c: ...this.
            * gcc.target/i386/pr128662-2.c: New test.

Reply via email to