public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH for fold-const.c
@ 1998-05-11 22:10 Mark Mitchell
  1998-05-14  1:04 ` Jeffrey A Law
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Mitchell @ 1998-05-11 22:10 UTC (permalink / raw)
  To: Jeff Law; +Cc: egcs

Jeff --

  Here's a patch for fold that avoids creating boolean type nodes that
are not boolean_{true,false}_node.  Is this OK?  Ideally, I don't
think there should be any INTEGER_CSTs of BOOLEAN_TYPE that are not
one of these two nodes.  At present, the C++ front-end implicitly
assumes this in at least one place.

-- 
Mark Mitchell <mmitchell@usa.net>
http://home.earthlink.net/~mbmitchell
Consulting Services Available

1998-05-11  Mark Mitchell  <mmitchell@usa.net>

	* fold-const.c (constant_boolean_node): New function.
	(fold): Use it.

Index: fold-const.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fold-const.c,v
retrieving revision 1.31
diff -c -p -r1.31 fold-const.c
*** fold-const.c	1998/05/06 21:07:05	1.31
--- fold-const.c	1998/05/12 05:03:41
*************** static tree unextend		PROTO((tree, int, 
*** 94,99 ****
--- 94,100 ----
  static tree fold_truthop	PROTO((enum tree_code, tree, tree, tree));
  static tree strip_compound_expr PROTO((tree, tree));
  static int multiple_of_p	PROTO((tree, tree, tree));
+ static tree constant_boolean_node PROTO((int, tree));
  
  #ifndef BRANCH_COST
  #define BRANCH_COST 1
*************** strip_compound_expr (t, s)
*** 3702,3707 ****
--- 3703,3729 ----
    return t;
  }
  \f
+ /* Return a node which has the indicated constant VALUE (either 0 or
+    1), and is of the indicated TYPE.  */
+ tree
+ constant_boolean_node (value, type)
+      int value;
+      tree type;
+  
+ {
+   if (type == integer_type_node)
+     return value ? integer_one_node : integer_zero_node;
+   else if (TREE_CODE (type) == BOOLEAN_TYPE)
+     return truthvalue_conversion (value ? integer_one_node :
+ 				  integer_zero_node); 
+   else 
+     {
+       tree t = build_int_2 (value, 0);
+       TREE_TYPE (t) = type;
+       return t;
+     }
+ }
+ 
  /* Perform constant folding and related simplification of EXPR.
     The related simplifications include x*1 => x, x*0 => 0, etc.,
     and application of the associative law.
*************** fold (expr) 
*** 5343,5356 ****
  	    case GE_EXPR:
  	    case LE_EXPR:
  	      if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
! 		{
! 		  if (type == integer_type_node)
! 		    return integer_one_node;
! 
! 		  t = build_int_2 (1, 0);
! 		  TREE_TYPE (t) = type;
! 		  return t;
! 		}
  	      code = EQ_EXPR;
  	      TREE_SET_CODE (t, code);
  	      break;
--- 5364,5370 ----
  	    case GE_EXPR:
  	    case LE_EXPR:
  	      if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
! 		return constant_boolean_node (1, type);
  	      code = EQ_EXPR;
  	      TREE_SET_CODE (t, code);
  	      break;
*************** fold (expr) 
*** 5362,5373 ****
  	      /* ... fall through ...  */
  	    case GT_EXPR:
  	    case LT_EXPR:
! 	      if (type == integer_type_node)
! 		return integer_zero_node;
! 
! 	      t = build_int_2 (0, 0);
! 	      TREE_TYPE (t) = type;
! 	      return t;
  	    default:
  	      abort ();
  	    }
--- 5376,5382 ----
  	      /* ... fall through ...  */
  	    case GT_EXPR:
  	    case LT_EXPR:
! 	      return constant_boolean_node (0, type);
  	    default:
  	      abort ();
  	    }

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

* Re: PATCH for fold-const.c
  1998-05-11 22:10 PATCH for fold-const.c Mark Mitchell
@ 1998-05-14  1:04 ` Jeffrey A Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey A Law @ 1998-05-14  1:04 UTC (permalink / raw)
  To: mmitchell; +Cc: egcs, wilson

  In message < 199805120512.WAA05711@mail.earthlink.net >you write:
  >   Here's a patch for fold that avoids creating boolean type nodes that
  > are not boolean_{true,false}_node.  Is this OK?  Ideally, I don't
  > think there should be any INTEGER_CSTs of BOOLEAN_TYPE that are not
  > one of these two nodes.  At present, the C++ front-end implicitly
  > assumes this in at least one place.
  > 
  > 
  > 1998-05-11  Mark Mitchell  <mmitchell@usa.net>
  > 
  > 	* fold-const.c (constant_boolean_node): New function.
  > 	(fold): Use it.
Looks reasonable to me.  Though I suspect there's more places we'll
eventually have to fix.

jeff

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

end of thread, other threads:[~1998-05-14  1:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-11 22:10 PATCH for fold-const.c Mark Mitchell
1998-05-14  1:04 ` Jeffrey A Law

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).