This is the mail archive of the gcc-patches@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]

Fix xstormy16 handling of HImode predicates


xstormy16 has:

(define_predicate "xs_hi_general_operand"
  (match_code "const_int,reg,subreg,mem,symbol_ref,label_ref,const")
{
  if ((GET_CODE (op) == CONST_INT)
       && ((INTVAL (op) >= 32768) || (INTVAL (op) < -32768)))
    {
      error ("constant halfword load operand out of range");
      return false;
    }
    
  return general_operand (op, mode);
})

I think this is wrong for two reasons:

- Predicates are supposed to accept things in different modes and weed out
  the invalid values.  That's why the predicates start with a check that
  GET_MODE (op) == VOIDmode || GET_MODE (op) == mode.

  IMO it doesn't make sense to handle (e.g.) SImode REGs correctly but
  raise an error for SImode CONST_INTs.  The generic predicates later
  reject CONST_INTs that aren't suitable for the mode, so invalid
  HImode CONST_INTs will fail to match rather than be silently accepted.

- If we did have a check, it should be an assert rather than a user error.

The port is effectively relying on the matching algorithm in genrecog to
ensure that the predicate is only called on SET_SRC rtxes once the mode
of the SET_DEST has been checked.

This patch removes the predicate and uses general_operand instead.

xs_hi_nonmemory_operand is similar except that it rejects symbol_ref
and label_ref constants.  The patch therefore removes the error check
but keeps the restricted code list.

Note that we have an assert in rtl.h that CONST_INTs fit into the
range appropriate for the wi:: precision.  This should catch more
cases than the predicate checks would have.  (It has flagged up
problems that were latent before.)

Tested by building xstormy16-elf and making sure that there were
no differences in assembly output for the GCC testsuite.
OK to install?

Thanks,
Richard


gcc/
	* config/stormy16/predicates.md (xs_hi_general_operand): Delete.
	(xs_hi_nonmemory_operand): Remove error.
	* config/stormy16/stormy16.md (movhi, movhi_internal): Use
	general_operand rather than xs_hi_general_operand.

Index: gcc/config/stormy16/predicates.md
===================================================================
--- gcc/config/stormy16/predicates.md	2015-04-27 10:38:48.000000000 +0100
+++ gcc/config/stormy16/predicates.md	2015-04-27 10:40:00.709344494 +0100
@@ -151,28 +151,8 @@ (define_predicate "xstormy16_carry_plus_
 	  && (INTVAL (XEXP (op, 1)) < -4 || INTVAL (XEXP (op, 1)) > 4));
 })
 
-(define_predicate "xs_hi_general_operand"
-  (match_code "const_int,reg,subreg,mem,symbol_ref,label_ref,const")
-{
-  if ((GET_CODE (op) == CONST_INT)
-       && ((INTVAL (op) >= 32768) || (INTVAL (op) < -32768)))
-    {
-      error ("constant halfword load operand out of range");
-      return false;
-    }
-    
-  return general_operand (op, mode);
-})
-
 (define_predicate "xs_hi_nonmemory_operand"
   (match_code "const_int,reg,subreg,const")
 {
-  if ((GET_CODE (op) == CONST_INT) 
-       && ((INTVAL (op) >= 32768) || (INTVAL (op) < -32768)))
-    {
-      error ("constant arithmetic operand out of range");
-      return false;
-    }
-
   return nonmemory_operand (op, mode);
 })
Index: gcc/config/stormy16/stormy16.md
===================================================================
--- gcc/config/stormy16/stormy16.md	2015-04-27 10:38:48.000000000 +0100
+++ gcc/config/stormy16/stormy16.md	2015-04-27 10:40:00.709344494 +0100
@@ -185,7 +185,7 @@ (define_insn "pophi1"
 
 (define_expand "movhi"
   [(set (match_operand:HI 0 "nonimmediate_nonstack_operand" "")
-	(match_operand:HI 1 "xs_hi_general_operand" ""))]
+	(match_operand:HI 1 "general_operand" ""))]
   ""
   { xstormy16_expand_move (HImode, operands[0], operands[1]);
     DONE;
@@ -193,7 +193,7 @@ (define_expand "movhi"
 
 (define_insn "movhi_internal"
   [(set (match_operand:HI 0 "nonimmediate_nonstack_operand" "=r,m,e,e,T,r,S,W,e")
-	(match_operand:HI 1 "xs_hi_general_operand"          "r,e,m,L,L,i,i,ie,W"))]
+	(match_operand:HI 1 "general_operand"                "r,e,m,L,L,i,i,ie,W"))]
   ""
   "@
    mov %0,%1


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