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 rtl-optimization/68282] Optimization fails to remove unnecessary sign extension instruction


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Target|                            |x86_64-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-11-11
          Component|other                       |rtl-optimization
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The reason this is not needed is that c >> 2 + 1 cannot be > 255.  Note that I
see

func:
.LFB0:
        .cfi_startproc
        shrb    $2, %dil
        leaq    1(%rdi), %rax
        andl    $127, %eax
        movl    table(,%rax,4), %eax
        ret

but similar the andl is not needed here.  Not sure where that comes from as
we expand from

func (unsigned char c)
{
  unsigned char _2;
  int _3;
  int _4;
  int _6;

  <bb 2>:
  _2 = c_1(D) >> 2;
  _3 = (int) _2;
  _4 = _3 + 1;
  _6 = table[_4];
  return _6;

(insn 8 7 9 (parallel [
            (set (reg:QI 95)
                (lshiftrt:QI (reg/v:QI 91 [ c ])
                    (const_int 2 [0x2])))
            (clobber (reg:CC 17 flags))
        ]) t.c:5 -1
     (nil))

(insn 9 8 10 (set (reg:SI 96)
        (zero_extend:SI (reg:QI 95))) t.c:5 -1
     (nil))

(insn 10 9 11 (parallel [
            (set (reg:SI 97)
                (plus:SI (reg:SI 96)
                    (const_int 1 [0x1])))
            (clobber (reg:CC 17 flags))
        ]) t.c:5 -1
     (nil))

(insn 11 10 12 (set (reg:DI 98)
        (sign_extend:DI (reg:SI 97))) t.c:5 -1
     (nil))

(insn 12 11 13 (set (reg:SI 99)
        (mem:SI (plus:DI (mult:DI (reg:DI 98)
                    (const_int 4 [0x4]))
                (reg/f:DI 94)) [1 table S4 A32])) t.c:5 -1
     (nil))

I wonder how we conclude that exchanging the zero-extend with the plus is ok.

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