diff mbox

[i386] : Combine memory and indirect jump

Message ID CAEwic4brJeBvoe+J5ss=Qo+=qoo-=2nV0FnjdUxBhm-fV4aqeQ@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz June 11, 2014, 8:32 a.m. UTC
Hello,

this patch adds simple combining of indirect-jumps on memory-address.
This patch is pretty similar to sibcall-combing.
ChangeLog

2014-06-11  Kai Tietz  <ktietz@redhat.com>

    * config/i386/i386.md (peehole2): To combine
    indirect jump with memory.

2014-06-11  Kai Tietz  <ktietz@redhat.com>

    * gcc.target/i386/indjmp-1.c: New test.

Tested for i686-pc-cygwin, and x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Comments

Steven Bosscher June 11, 2014, 9:57 a.m. UTC | #1
On Wed, Jun 11, 2014 at 10:32 AM, Kai Tietz wrote:
> this patch adds simple combining of indirect-jumps on memory-address.
> This patch is pretty similar to sibcall-combing.
> ChangeLog
>
> 2014-06-11  Kai Tietz  <ktietz@...>
>
>     * config/i386/i386.md (peehole2): To combine
>     indirect jump with memory.


Likely fixes part of PR39284, xf. https://gcc.gnu.org/PR39284#c12

Ciao!
Steven
Kai Tietz June 11, 2014, 10:37 a.m. UTC | #2
2014-06-11 11:57 GMT+02:00 Steven Bosscher <stevenb.gcc@gmail.com>:
> On Wed, Jun 11, 2014 at 10:32 AM, Kai Tietz wrote:
>> this patch adds simple combining of indirect-jumps on memory-address.
>> This patch is pretty similar to sibcall-combing.
>> ChangeLog
>>
>> 2014-06-11  Kai Tietz  <ktietz@...>
>>
>>     * config/i386/i386.md (peehole2): To combine
>>     indirect jump with memory.
>
>
> Likely fixes part of PR39284, xf. https://gcc.gnu.org/PR39284#c12
>
> Ciao!
> Steven

Well, it fixes it just partial AFAICS.  Btw PR target/51840 is related
to the same issue too.

Latter problem shows much better the underlying issue of
jump-shortening. Issue is here that the jump to a jump (or better said
indirect jump) isn't shortened.

Regards,
Kai
diff mbox

Patch

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md    (Revision 211409)
+++ config/i386/i386.md    (Arbeitskopie)
@@ -11471,6 +11471,40 @@ 
             (match_dup 3))
           (set (reg:SI SP_REG) (match_dup 4))])])

+;; Combining simple memory jump instruction
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand")
+        (match_operand:SI 1 "memory_nox32_operand"))
+   (set (pc) (match_dup 0))]
+  "!TARGET_64BIT && peep2_reg_dead_p (2, operands[0])"
+  [(set (pc) (match_dup 1))])
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand")
+        (match_operand:SI 1 "memory_nox32_operand"))
+   (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (set (pc) (match_dup 0))]
+  "!TARGET_64BIT && peep2_reg_dead_p (3, operands[0])"
+  [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (set (pc) (match_dup 1))])
+
+(define_peephole2
+  [(set (match_operand:DI 0 "register_operand")
+        (match_operand:DI 1 "memory_nox32_operand"))
+   (set (pc) (match_dup 0))]
+  "TARGET_64BIT && peep2_reg_dead_p (2, operands[0])"
+  [(set (pc) (match_dup 1))])
+
+(define_peephole2
+  [(set (match_operand:DI 0 "register_operand")
+        (match_operand:DI 1 "memory_nox32_operand"))
+   (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (set (pc) (match_dup 0))]
+  "TARGET_64BIT && peep2_reg_dead_p (3, operands[0])"
+  [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (set (pc) (match_dup 1))])
+
 ;; Call subroutine, returning value in operand 0

 (define_expand "call_value"
Index: testsuite/gcc.target/i386/indjmp-1.c
===================================================================
--- testsuite/gcc.target/i386/indjmp-1.c    (Revision 0)
+++ testsuite/gcc.target/i386/indjmp-1.c    (Arbeitskopie)
@@ -0,0 +1,23 @@ 
+/* { dg-do compile  { target ia32 } } */
+/* { dg-options "-O2" } */
+
+#define ADVANCE_AND_DISPATCH() goto *addresses[*pc++]
+
+void
+Interpret(const unsigned char *pc)
+{
+    static const void *const addresses[] = {
+      &&l0, &&l1, &&l2
+    };
+
+l0:
+    ADVANCE_AND_DISPATCH();
+
+l1:
+    ADVANCE_AND_DISPATCH();
+
+l2:
+    return;
+}
+
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*.%eax" } } */