[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2021-05-30 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread segher at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

--- Comment #6 from Segher Boessenkool  ---
There is also SELECT_CC_MODE.

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread segher at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

--- Comment #5 from Segher Boessenkool  ---
Various things can change the comparison mode.  simplify_compare_const
is the most prominent example (hrm, maybe the only one now?)

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread ubizjak at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

--- Comment #4 from Uroš Bizjak  ---
(In reply to Segher Boessenkool from comment #3)
> What is the question?  4+4 = 16?

Ah, indeed - the question is why combine changes CCCmode compare to CCZmode
compare.

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread segher at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

--- Comment #3 from Segher Boessenkool  ---
What is the question?  4+4 = 16?  Not all costs are included in
that "4+4" :-)  It does look weird; patches welcome.

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread ubizjak at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

Uroš Bizjak  changed:

   What|Removed |Added

 CC||segher at gcc dot gnu.org

--- Comment #2 from Uroš Bizjak  ---
Adding Segher to CC.

[Bug target/95531] Failure to use TZCNT for __builtin_ffs

2020-06-04 Thread ubizjak at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95531

--- Comment #1 from Uroš Bizjak  ---
So, what kind of sorcery is this?

(insn 2 4 3 2 (set (reg/v:SI 83 [ x ])
(reg:SI 5 di [ x ])) "pr95531.c":2:1 67 {*movsi_internal}
 (expr_list:REG_DEAD (reg:SI 5 di [ x ])
(nil)))

(...)

(insn 7 6 8 2 (parallel [
(set (reg:CCC 17 flags)
(compare:CCC (reg/v:SI 83 [ x ])
(const_int 0 [0])))
(set (reg:SI 82 [  ])
(ctz:SI (reg/v:SI 83 [ x ])))
]) "pr95531.c":3:12 786 {*tzcntsi_1}
 (expr_list:REG_DEAD (reg/v:SI 83 [ x ])
(nil)))
(insn 8 7 9 2 (set (reg:SI 82 [  ])
(if_then_else:SI (eq (reg:CCC 17 flags)
(const_int 0 [0]))
(reg:SI 84)
(reg:SI 82 [  ]))) "pr95531.c":3:12 1029 {*movsicc_noc}
 (expr_list:REG_DEAD (reg:SI 84)
(expr_list:REG_DEAD (reg:CCC 17 flags)
(nil

Combine does:

Trying 2 -> 7:
2: r83:SI=r86:SI
  REG_DEAD r86:SI
7: {flags:CCC=cmp(r83:SI,0);r82:SI=ctz(r83:SI);}
  REG_DEAD r83:SI
Successfully matched this instruction:
(parallel [
(set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 86)
(const_int 0 [0])))
(set (reg:SI 82 [  ])
(ctz:SI (reg:SI 86)))
])
Successfully matched this instruction:
(set (reg:SI 82 [  ])
(if_then_else:SI (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(reg:SI 84)
(reg:SI 82 [  ])))
allowing combination of insns 2 and 7
original costs 4 + 4 = 16
replacement cost 12
deferring deletion of insn with uid = 2.
modifying other_insn 8: r82:SI={(flags:CCZ==0)?r84:SI:r82:SI}
  REG_DEAD r84:SI
  REG_DEAD flags:CCC
deferring rescan insn with uid = 8.
modifying insn i3 7: {flags:CCZ=cmp(r86:SI,0);r82:SI=ctz(r86:SI);}
  REG_DEAD r86:SI
deferring rescan insn with uid = 7.

Combine changes CCCmode comparison to CCZmode.