Patchwork PATCH: Properly check mode for x86 call/jmp address

login
register
mail settings
Submitter Uros Bizjak
Date March 7, 2012, 10:12 a.m.
Message ID <CAFULd4ZNL7HsptOHMcAhw1rZbVjt36F-Qc4Uh3vJRXw3JTbrnw@mail.gmail.com>
Download mbox | patch
Permalink /patch/145182/
State New
Headers show

Comments

Uros Bizjak - March 7, 2012, 10:12 a.m.
On Wed, Mar 7, 2012 at 11:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Wed, Mar 7, 2012 at 10:28 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>
>> +  if (TARGET_X32)
>> +    operands[0] = convert_memory_address (word_mode, operands[0]);
>>
>> This addition to indirect_jump and tablejump should be the only
>> change, needed in i386.md now. Please write the condition
>>
>> if (Pmode != word_mode)
>>
>> for consistency.
>
> Ah, I vaguely remember that indirect call/jmp is invalid on X32 for
> some other reason. So, please leave the condition above as is and also
> revert similar change in attached patch back to (not (match_test
> "TARGET_X32")).

Now with attached predicate.md patch.

Uros.

Patch

Index: predicates.md
===================================================================
--- predicates.md	(revision 184992)
+++ predicates.md	(working copy)
@@ -1,5 +1,5 @@ 
 ;; Predicate definitions for IA-32 and x86-64.
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
 ;; Free Software Foundation, Inc.
 ;;
 ;; This file is part of GCC.
@@ -557,22 +565,27 @@ 
        (match_operand 0 "immediate_operand")))
 
 ;; Test for a valid operand for indirect branch.
+;; Allow register operands in word mode only.
 (define_predicate "indirect_branch_operand"
-  (if_then_else (match_test "TARGET_X32")
-    (match_operand 0 "register_operand")
-    (match_operand 0 "nonimmediate_operand")))
+  (ior (match_test "register_operand
+		     (op, mode == VOIDmode ? mode : word_mode)")
+       (and (not (match_test "TARGET_X32"))
+	    (match_operand 0 "memory_operand"))))
 
 ;; Test for a valid operand for a call instruction.
+;; Allow register operands in word mode only.
 (define_predicate "call_insn_operand"
   (ior (match_operand 0 "constant_call_address_operand")
-       (match_operand 0 "call_register_no_elim_operand")
+       (match_test "call_register_no_elim_operand
+		     (op, mode == VOIDmode ? mode : word_mode)")
        (and (not (match_test "TARGET_X32"))
 	    (match_operand 0 "memory_operand"))))
 
 ;; Similarly, but for tail calls, in which we cannot allow memory references.
 (define_predicate "sibcall_insn_operand"
   (ior (match_operand 0 "constant_call_address_operand")
-       (match_operand 0 "register_no_elim_operand")))
+       (match_test "register_no_elim_operand
+		     (op, mode == VOIDmode ? mode : word_mode)")))
 
 ;; Match exactly zero.
 (define_predicate "const0_operand"