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]

New gensimplify



This gensimplify's RTL generation is pretty rock solid. I've been
using it for days on all kinds of code (recompiling all kinds of
stuff) without any trouble.

The simplifiers for trees it generates are correct, at least, as far
as i know, and have verified they operate at the right times, and do
the right things.  However, i'm a lot less confident in it, because of
how it had to be implemented, than i am of the RTL stuff, at this
stage.
In other words, i'm pretty sure you could break it if you tried hard
enough (Though i'm tripped across what i believe to be most of the
actual bugs, there are some implementation details that may cause it
to trip up).

So at this point, i'm still looking for comments, rather than approval.

Before I take the plunge and clean up the tree simplification stuff,
recomment and whatnot, etc, i need a little advice.

i'm thinking we can handle just about all of the cases we want to
handle without a define_simplify_tree_only, with 
the right combination of mapping and predicates, can someone tell me
if i'm just flat out on crack here thinking this is the way to go?

An example of a tree simplifier that uses predicates and a kludge
(merging the RTL codes that will become equivalent tree codes to a
single RTL code to avoid a duplicate case statement) because two RTL
codes map back to the same tree code would be something using ASHIFTRT and LSHIFTRT.
These map to a tree code of RSHIFT_EXPR, with a predicate of signed or
unsigned tree operand, as approriate (this is how trees differentiate
between the two types of shifts).
So you have to handle the fact that the base codes differ in RTL, but not in
trees, and need a special predicate in trees instead.
Which we do.
--Dan

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/Makefile.in,v
retrieving revision 1.663
diff -c -3 -p -w -B -b -r1.663 Makefile.in
*** Makefile.in	2001/05/16 19:05:49	1.663
--- Makefile.in	2001/05/17 03:19:29
*************** C_OBJS = c-parse.o c-lang.o $(C_AND_OBJC
*** 732,751 ****
  
  OBJS =									\
   alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o		\
!  combine.o conflict.o convert.o cse.o cselib.o dbxout.o dce.o		\
!  dependence.o diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o	\
   dwarfout.o emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o	\
!  fold-const.o function.o gcse.o genrtl.o ggc-common.o global.o graph.o	\
!  haifa-sched.o hash.o ifcvt.o insn-attrtab.o insn-emit.o		\
!  insn-extract.o insn-opinit.o insn-output.o insn-peep.o insn-recog.o	\
   integrate.o intl.o jump.o lcm.o lists.o local-alloc.o loop.o mbchar.o	\
   optabs.o params.o predict.o print-rtl.o print-tree.o profile.o real.o	\
   recog.o reg-stack.o regclass.o regmove.o regrename.o reload.o		\
   reload1.o reorg.o resource.o rtl.o rtlanal.o sbitmap.o sched-deps.o	\
   sched-ebb.o sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o	\
   splay-tree.o ssa.o stmt.o stor-layout.o stringpool.o timevar.o		\
!  toplev.o tree.o unroll.o varasm.o varray.o version.o xcoffout.o	\
!  $(GGC) $(out_object_file) $(EXTRA_OBJS)
  
  BACKEND = main.o libbackend.a
  
--- 732,751 ----
  
  OBJS =									\
   alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o		\
!  combine.o conflict.o convert.o cse.o cselib.o dbxout.o dce.o		\
!  dependence.o diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o	\
   dwarfout.o emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o	\
!  fold-const.o function.o gcse.o genrtl.o ggc-common.o global.o graph.o 	\
!  haifa-sched.o hash.o ifcvt.o insn-attrtab.o insn-emit.o insn-recog.o	\
!  insn-extract.o insn-opinit.o insn-output.o insn-peep.o test.o 	\
   integrate.o intl.o jump.o lcm.o lists.o local-alloc.o loop.o mbchar.o	\
   optabs.o params.o predict.o print-rtl.o print-tree.o profile.o real.o	\
   recog.o reg-stack.o regclass.o regmove.o regrename.o reload.o		\
   reload1.o reorg.o resource.o rtl.o rtlanal.o sbitmap.o sched-deps.o	\
   sched-ebb.o sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o	\
   splay-tree.o ssa.o stmt.o stor-layout.o stringpool.o timevar.o		\
!  toplev.o tree.o unroll.o varasm.o varray.o version.o xcoffout.o	\
!  new-simplify.o $(GGC) $(out_object_file) $(EXTRA_OBJS)
  
  BACKEND = main.o libbackend.a
  
*************** BACKEND = main.o libbackend.a
*** 755,761 ****
  GEN= genemit$(build_exeext) genoutput$(build_exeext) genrecog$(build_exeext) \
   genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext)   \
   genconfig$(build_exeext) genpeep$(build_exeext) gengenrtl$(build_exeext)    \
!  gencheck$(build_exeext)
  
  # Files to be copied away after each stage in building.
  STAGESTUFF = *$(objext) insn-flags.h insn-config.h insn-codes.h \
--- 755,761 ----
  GEN= genemit$(build_exeext) genoutput$(build_exeext) genrecog$(build_exeext) \
   genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext)   \
   genconfig$(build_exeext) genpeep$(build_exeext) gengenrtl$(build_exeext)    \
!  gencheck$(build_exeext) gensimplify$(build_exeext)
  
  # Files to be copied away after each stage in building.
  STAGESTUFF = *$(objext) insn-flags.h insn-config.h insn-codes.h \
*************** STAGESTUFF = *$(objext) insn-flags.h ins
*** 768,774 ****
   genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext) \
   genconfig$(build_exeext) genpeep$(build_exeext) genattrtab$(build_exeext) \
   genattr$(build_exeext) genopinit$(build_exeext) gengenrtl$(build_exeext) \
!  gencheck$(build_exeext) genrtl.c genrtl.h \
   xgcc$(exeext) cpp$(exeext) cc1$(exeext) cpp0$(exeext) $(EXTRA_PASSES) \
   $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) cc1obj$(exeext) \
   enquire$(exeext) protoize$(exeext) unprotoize$(exeext) \
--- 768,774 ----
   genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext) \
   genconfig$(build_exeext) genpeep$(build_exeext) genattrtab$(build_exeext) \
   genattr$(build_exeext) genopinit$(build_exeext) gengenrtl$(build_exeext) \
!  gencheck$(build_exeext) gensimplify$(build_exeext) genrtl.c genrtl.h \
   xgcc$(exeext) cpp$(exeext) cc1$(exeext) cpp0$(exeext) $(EXTRA_PASSES) \
   $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) cc1obj$(exeext) \
   enquire$(exeext) protoize$(exeext) unprotoize$(exeext) \
*************** s-recog : $(md_file) genrecog$(build_exe
*** 1665,1670 ****
--- 1674,1685 ----
  	$(SHELL) $(srcdir)/move-if-change tmp-recog.c insn-recog.c
  	$(STAMP) s-recog
  
+ new-simplify.c: s-simplify ; @true
+ s-simplify : simplify.md gensimplify$(build_exeext) $(srcdir)/move-if-change
+ 	./gensimplify$(build_exeext) $(srcdir)/simplify.md > tmp-simplify.c
+ 	$(SHELL) $(srcdir)/move-if-change tmp-simplify.c new-simplify.c
+ 	$(STAMP) s-simplify
+ 
  insn-opinit.o : insn-opinit.c $(CONFIG_H) $(RTL_H) \
    insn-config.h flags.h $(RECOG_H) $(EXPR_H) reload.h $(SYSTEM_H)
  	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-opinit.c
*************** genopinit.o : genopinit.c $(RTL_H) $(HCO
*** 1797,1808 ****
    $(SYSTEM_H) errors.h gensupport.h
  	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genopinit.c
  
  genrecog$(build_exeext) : genrecog.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
  	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
  	 genrecog.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS)
  
  genrecog.o : genrecog.c $(RTL_H) $(HCONFIG_H) \
!   $(SYSTEM_H) errors.h gensupport.h
  	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genrecog.c
  
  genextract$(build_exeext) : genextract.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
--- 1812,1832 ----
    $(SYSTEM_H) errors.h gensupport.h
  	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genopinit.c
  
+ gensimplify$(build_exeext) : gensimplify.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS) 
+ 	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
+ 	 gensimplify.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS) 
+ 
+ gensimplify.o : gensimplify.c $(RTL_H) $(HCONFIG_H) \
+   $(SYSTEM_H) errors.h gensupport.h
+ 	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gensimplify.c
+ 
+ 
  genrecog$(build_exeext) : genrecog.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
  	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
  	 genrecog.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS)
  
  genrecog.o : genrecog.c $(RTL_H) $(HCONFIG_H) \
!   $(SYSTEM_H) errors.h gensupport.h recog.h
  	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genrecog.c 
  
  genextract$(build_exeext) : genextract.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
Index: simplify.md
===================================================================
RCS file: simplify.md
diff -N simplify.md
*** /dev/null	Tue May  5 13:32:27 1998
--- simplify.md	Wed May 16 20:19:29 2001
***************
*** 0 ****
--- 1,177 ----
+ ;;; This is almost exactly the define_peephole2 syntax,
+ ;;; the differences are the string for the rule name
+ ;;; and i dont think scratch registers work (I removed the code, so id
+ ;;; be pretty surprised if they work)
+ ;; Simplifications for ABS:
+ (define_simplify  "abs-abs"
+ [(abs (abs (match_operand 0 "" "")))]
+ ""
+ [(abs (match_dup 0))]
+ ""
+ )
+ 
+ (define_simplify "abs-neg"
+ [(abs (neg (match_operand 0 "" "")))]
+ ""
+ [(abs (match_dup 0))]
+ ""
+ )
+ ;; Simplification for unary -
+ (define_simplify  "-(-x)"
+ [(neg (neg (match_operand 0 "" "")))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ 
+ (define_simplify "-(x-y)"
+ [(neg (minus (match_operand 0 "" "") (match_operand 1 "" "")))]
+ ""
+ [(minus (match_dup 1) (match_dup 0))]
+ ""
+ )
+ 
+ (define_simplify "-(x*c1)"
+ [(neg (mult (match_operand 0 "" "") (match_operand 1 "immediate_operand" "")))]
+ ""
+ [(mult (match_dup 0) (neg (match_dup 1)))]
+ ""
+ )
+ 
+ (define_simplify "-(x/c1)"
+ [(neg (div (match_operand 0 "" "") (match_operand 1 "immediate_operand" "")))]
+ ""
+ [(div (match_dup 0) (neg (match_dup 1)))]
+ ""
+ )
+ 
+ (define_simplify "-(c1/x)"
+ [(neg (div (match_operand 0 "immediate_operand" "") (match_operand 1 "" "")))]
+ ""
+ [(div (neg (match_dup 0)) (match_dup 1))]
+ ""
+ )
+ 
+ ;; Simplifications for ~
+ 
+ (define_simplify "not-not"
+ [(not (not (match_operand 0 "" "")))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ (define_simplify "~(a nor b)"
+ [(not (ior (not (match_operand 0 "" "")) (not (match_operand 1 "" ""))))]
+ ""
+ [(ior (match_dup 0) (match_dup 1))]
+ ""
+ )
+ 
+ (define_simplify "~(a | b)"
+ [(not (ior (match_operand 0 "" "") (match_operand 1 "" "")))]
+ ""
+ [(ior (not (match_dup 0)) (not (match_dup 1)))]
+ ""
+ )
+ ;; Simplifications for +, -
+ 
+ 
+ (define_simplify "x + (-y)"
+ [(plus (match_operand 0 "" "") (neg (match_operand 1 "" "")))]
+ ""
+ [(minus (match_dup 0) (match_dup 1))]
+ ""
+ )
+ 
+ (define_simplify "x - (-y)"
+ [(minus (match_operand 0 "" "") (neg (match_operand 1 "" "")))]
+ ""
+ [(plus (match_dup 0) (match_dup 1))]
+ ""
+ )
+ 
+ (define_simplify "x + 0"
+ [(plus (match_operand 0 "" "") (const_int 0))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ 
+ (define_simplify "x - 0"
+ [(minus (match_operand 0 "" "") (const_int 0))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ 
+ (define_simplify "0 - x"
+ [(minus (const_int 0) (match_operand 0 "" ""))]
+ ""
+ [(neg (match_dup 0))]
+ ""
+ )
+ 
+ (define_simplify "-x - y"
+ [(minus (neg (match_operand 0 "" "")) (match_operand 1 "" ""))]
+ ""
+ [(neg (plus (match_dup 0) (match_dup 1)))]
+ ""
+ )
+ 
+ (define_simplify "-x + y"
+ [(plus (neg (match_operand 0 "" "")) (match_operand 1 "" ""))]
+ ""
+ [(minus (match_dup 1) (match_dup 0))]
+ ""
+ )
+ 
+ (define_simplify "x - c"
+ [(minus (match_operand 0 "" "") (match_operand 1 "const_double_operand" ""))]
+ ""
+ [(plus (match_dup 0) (neg (match_dup 1)))]
+ )
+ 
+ ;; Simplifications for *
+ 
+ 
+ (define_simplify "x * 1"
+ [(mult (match_operand 0 "" "") (const_int 1))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ 
+ (define_simplify "x * -1"
+ [(mult (match_operand 0 "" "") (const_int -1))]
+ ""
+ [(neg  (match_dup 0))]
+ ""
+ )
+ 
+ (define_simplify "j ^ 0"
+ [(xor (match_operand 0 "" "") (const_int 0))]
+ ""
+ [(match_dup 0)]
+ ""
+ )
+ 
+ (define_simplify "j ^ -1"
+ [(xor (match_operand 0 "" "") (const_int -1))]
+ ""
+ [(not (match_dup 0))]
+ ""
+ )
+ ;; Simplifications for ||
+ ;;(define_simplify "j || 0"
+ ;;[(ior (match_operand 0 "" "") (const_int 0))]
+ ;;""
+ ;;[(match_dup 0)]
+ ;;""
+ ;;)
+ 
+ ;;(define_simplify "j || 1"
+ ;;[(ior (match_operand 0 "" "") (const_int 1))]
+ ;;""
+ ;;[(const_int 1)]
+ ;;""
+ ;;)

gensimplify.c.gz


-- 
"When I was a baby, I kept a diary.  Recently, I was rereading
it.  It said, "Day 1 -- Still tired from the move.  Day 2 --
Everybody talks to me like I'm an idiot."
"-Steven Wright

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