This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/86975] New: wrong peephole optimization applied on nios2 and mips targets


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

            Bug ID: 86975
           Summary: wrong peephole optimization applied on nios2 and mips
                    targets
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: already5chosen at yahoo dot com
  Target Milestone: ---

On MIPS and Nios2 architectures logical instruction immediate (andi, ori)
zero-extend immediate field. It means that on this targets small negative
constants in logical expressions are more expensive than small (or not so
small) positive constants. Peephole optimization phase should take it into
account when selecting substitution patterns, but right now it's not smart
enough.

Code:

int isE(int x) { return (x=='e') || (x=='E') ; }

RISV32 (-Os -rv32im) :
00000000 <isE>:
   0:   fdf57513                andi    a0,a0,-33
   4:   fbb50513                addi    a0,a0,-69
   8:   00153513                seqz    a0,a0
   c:   8082                    ret

That's good, because RISC-V sign-extends field in logical instructions which
means that it has no problems with small integer constants.

MIPS ( -Os -mips32r6 -mcompact-branches=always) :
00000000 <isE>:
   0:   2402ffdf        li      v0,-33
   4:   00821024        and     v0,a0,v0
   8:   38420045        xori    v0,v0,0x45
   c:   2c420001        sltiu   v0,v0,1
  10:   d81f0000        jrc     ra

Nios2 (-Os) :
00000000 <isE>:
   0:   00bff7c4        movi    r2,-33
   4:   2084703a        and     r2,r4,r2
   8:   10801160        cmpeqi  r2,r2,69
   c:   f800283a        ret

That not so good. Both of them are sub-optimal. 
These targets should use substitution pattern based on small positive constant.
Like that:

MIPS:
00000000 <smarter_isE>:
   0:   34820020        ori     v0,a0,0x20
   4:   38420065        xori    v0,v0,0x65
   8:   2c420001        sltiu   v0,v0,1
   c:   d81f0000        jrc     ra

Nios2:
00000000 <smarter_isE>:
   0:   20800814        ori     r2,r4,32
   4:   10801960        cmpeqi  r2,r2,101
   8:   f800283a        ret

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]