public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/94850] New: Failure to optimize operation corresponding to shrd to shrd
@ 2020-04-29 14:33 gabravier at gmail dot com
  2020-04-29 14:43 ` [Bug rtl-optimization/94850] " gabravier at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2020-04-29 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94850
           Summary: Failure to optimize operation corresponding to shrd to
                    shrd
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

struct testStruct {
        uint64_t a;
        uint64_t b;
};

uint64_t f(testStruct t, int x)
{
        return ((t.a << (64 - x)) | (t.b >> (x)));
}

LLVM produces this : 

f(testStruct, int): # @f(testStruct, int)
  mov ecx, edx
  mov rax, rsi
  shrd rax, rdi, cl
  ret

GCC produces this :

f(testStruct, int):
  mov ecx, 64
  mov rax, rsi
  sub ecx, edx
  sal rdi, cl
  mov ecx, edx
  shr rax, cl
  or rax, rdi
  ret

A similar optimization can be done for shld for this code : 

uint64_t f(uint64_t a, uint64_t b, int x)
{
        return ((a << (x)) | (b >> (64 - x)));
}

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

* [Bug rtl-optimization/94850] Failure to optimize operation corresponding to shrd to shrd
  2020-04-29 14:33 [Bug rtl-optimization/94850] New: Failure to optimize operation corresponding to shrd to shrd gabravier at gmail dot com
@ 2020-04-29 14:43 ` gabravier at gmail dot com
  2020-04-29 17:01 ` [Bug target/94850] " rguenth at gcc dot gnu.org
  2020-04-29 21:24 ` segher at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2020-04-29 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
PS : The same optimization can apply to i686, just replace all occurences of
"64" with "32" and you could use shld/shrd there too

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

* [Bug target/94850] Failure to optimize operation corresponding to shrd to shrd
  2020-04-29 14:33 [Bug rtl-optimization/94850] New: Failure to optimize operation corresponding to shrd to shrd gabravier at gmail dot com
  2020-04-29 14:43 ` [Bug rtl-optimization/94850] " gabravier at gmail dot com
@ 2020-04-29 17:01 ` rguenth at gcc dot gnu.org
  2020-04-29 21:24 ` segher at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-29 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |segher at gcc dot gnu.org
          Component|rtl-optimization            |target
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-04-29
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Probably a missing combine helper or a non-canonical pattern.  It looks like

(define_insn "x86_64_shrd"
  [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
        (ior:DI (lshiftrt:DI (match_dup 0)
                  (match_operand:QI 2 "nonmemory_operand" "Jc"))
                (ashift:DI (match_operand:DI 1 "register_operand" "r")
                  (minus:QI (const_int 64) (match_dup 2)))))
   (clobber (reg:CC FLAGS_REG))]

it tries for example

Failed to match this instruction:
(parallel [
        (set (reg:DI 93)
            (ior:DI (ashift:DI (reg:DI 102)
                    (minus:QI (subreg:QI (reg:SI 95) 0)
                        (subreg:QI (reg/v:SI 92 [ x ]) 0)))
                (reg:DI 97)))
        (clobber (reg:CC 17 flags))
    ])

or

Failed to match this instruction:
(parallel [
        (set (reg:DI 93)
            (ior:DI (lshiftrt:DI (reg:DI 103)
                    (subreg:QI (reg/v:SI 92 [ x ]) 0))
                (ashift:DI (reg:DI 102)
                    (subreg:QI (reg:SI 94) 0))))
        (clobber (reg:CC 17 flags))
    ])

but the insn with basically four ops is likely too complex for combines
little mind.  Ah here:

(set (reg:DI 93)
    (ior:DI (lshiftrt:DI (reg:DI 103)
            (subreg:QI (reg/v:SI 92 [ x ]) 0))
        (ashift:DI (reg:DI 102)
            (minus:QI (subreg:QI (reg:SI 95) 0)
                (subreg:QI (reg/v:SI 92 [ x ]) 0)))))

but no (const 64) which is still separate here:

(insn 11 8 12 2 (set (reg:SI 95)
        (const_int 64 [0x40])) "y.c":8:31 67 {*movsi_internal}
     (nil))

not sure if combine could help out here by propagating constants?

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

* [Bug target/94850] Failure to optimize operation corresponding to shrd to shrd
  2020-04-29 14:33 [Bug rtl-optimization/94850] New: Failure to optimize operation corresponding to shrd to shrd gabravier at gmail dot com
  2020-04-29 14:43 ` [Bug rtl-optimization/94850] " gabravier at gmail dot com
  2020-04-29 17:01 ` [Bug target/94850] " rguenth at gcc dot gnu.org
@ 2020-04-29 21:24 ` segher at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: segher at gcc dot gnu.org @ 2020-04-29 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Did combine try combining four insns here?  If not, would it have helped?

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

end of thread, other threads:[~2020-04-29 21:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 14:33 [Bug rtl-optimization/94850] New: Failure to optimize operation corresponding to shrd to shrd gabravier at gmail dot com
2020-04-29 14:43 ` [Bug rtl-optimization/94850] " gabravier at gmail dot com
2020-04-29 17:01 ` [Bug target/94850] " rguenth at gcc dot gnu.org
2020-04-29 21:24 ` segher 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).