[Bug rtl-optimization/108070] New: failure to combine range test to bit test

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 12 10:12:54 GMT 2022


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.


More information about the Gcc-bugs mailing list