public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108070] New: failure to combine range test to bit test
@ 2022-12-12 10:12 rguenth at gcc dot gnu.org
  2022-12-12 10:16 ` [Bug rtl-optimization/108070] " tnfchris at gcc dot gnu.org
  2022-12-12 15:23 ` tnfchris at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-12 10:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108070
           Summary: failure to combine range test to bit test
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

(insn 8 7 11 2 (parallel [ 
            (set (reg:QI 89)
                (and:QI (reg:QI 90 [ *info_6(D) ]) 
                    (const_int 3 [0x3])))
            (clobber (reg:CC 17 flags))
        ])
"/home/rguenther/src/trunk/gcc/testsuite/c-c++-common/fold-masked-cmp-1.c":37:7
554 {*andqi_1}
     (expr_list:REG_DEAD (reg:QI 90 [ *info_6(D) ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
(insn 11 8 12 2 (set (reg:CC 17 flags)
        (compare:CC (reg:QI 89)
            (const_int 1 [0x1])))
"/home/rguenther/src/trunk/gcc/testsuite/c-c++-common/fold-masked-cmp-1.c":37:6
9 {*cmpqi_1}
     (expr_list:REG_DEAD (reg:QI 89) 
        (nil)))  
(jump_insn 12 11 13 2 (set (pc)
        (if_then_else (gtu (reg:CC 17 flags)
                (const_int 0 [0]))
            (label_ref 15)
            (pc)))
"/home/rguenther/src/trunk/gcc/testsuite/c-c++-common/fold-masked-cmp-1.c":37:6
974 {*jcc}
     (expr_list:REG_DEAD (reg:CC 17 flags)
        (int_list:REG_BR_PROB 633507684 (nil)))
 -> 15) 

here insns 8, 11 and 12 should be combined to

(insn 7 6 8 2 (parallel [
            (set (reg:QI 88) 
                (and:QI (reg:QI 89 [ *info_7(D) ])
                    (const_int 2 [0x2])))
            (clobber (reg:CC 17 flags))
        ])
"/home/rguenther/src/gcc-12-branch/gcc/testsuite/c-c++-common/fold-masked-cmp-1.c":37:7
534 {*andqi_1}
     (expr_list:REG_DEAD (reg:QI 89 [ *info_7(D) ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
(insn 8 7 9 2 (set (reg:CCZ 17 flags)
        (compare:CCZ (reg:QI 88) 
            (const_int 0 [0])))
"/home/rguenther/src/gcc-12-branch/gcc/testsuite/c-c++-common/fold-masked-cmp-1.c":37:6
5 {*cmpqi_ccno_1}
     (expr_list:REG_DEAD (reg:QI 88)
        (nil)))

the jump also needs altering here.  This is required to avoid regressing
code like c-c++-common/fold-masked-cmp-1.c when
applying https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608153.html
where we no longer fold

;; Function test_exe (null)
;; enabled by -tree-original


{
  if (info->type <= 1)

to

;; Function test_exe (null)
;; enabled by -tree-original


{ 
  if ((BIT_FIELD_REF <*info, 8, 0> & 2) == 0)

note that applying this folding on GIMPLE produces a more costly operation
(we need an extra BIT_AND_EXPR here).  On x86_64 the folded code produces

        testb   $2, (%rdi)
        jne     .L8 

while the unfolded has

        movzbl  (%rdi), %eax
        andl    $3, %eax
        cmpb    $1, %al
        ja      .L5

as CC modes are involved I'm not sure if combine is the correct vehicle to
perform this.  IIRC arm folks wanted to add some bit-test-and-branch
patterns (that doesn't seem to be applied yet) which could make it possible
to optimize this during RTL expansion itself.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/108070] failure to combine range test to bit test
  2022-12-12 10:12 [Bug rtl-optimization/108070] New: failure to combine range test to bit test rguenth at gcc dot gnu.org
@ 2022-12-12 10:16 ` tnfchris at gcc dot gnu.org
  2022-12-12 15:23 ` tnfchris at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2022-12-12 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
Yes it's all been approved now, doing a regression after a rebase and will
commit today.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/108070] failure to combine range test to bit test
  2022-12-12 10:12 [Bug rtl-optimization/108070] New: failure to combine range test to bit test rguenth at gcc dot gnu.org
  2022-12-12 10:16 ` [Bug rtl-optimization/108070] " tnfchris at gcc dot gnu.org
@ 2022-12-12 15:23 ` tnfchris at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2022-12-12 15:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
Committed, implementing the tbranch optab should allow this to be fixed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-12 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 10:12 [Bug rtl-optimization/108070] New: failure to combine range test to bit test rguenth at gcc dot gnu.org
2022-12-12 10:16 ` [Bug rtl-optimization/108070] " tnfchris at gcc dot gnu.org
2022-12-12 15:23 ` tnfchris at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).