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]

i386 string compare peephole, revised


I think this version addresses all the issues discussed here.  Also, I
added a second peephole to catch cmpstrqi_1; the original pattern only
dealt with cmpstrqi_nz_1.  And I took out a bunch of :SI suffixes in
hopes of making the peepholes trigger on x86-64 as well as -32.  I
still don't know what to do about the case where there's notes and a
set of ebx in the middle of the peephole sequence, but they don't come
up that often, so we can live with them until this can be dealt with
properly, in combine.

Barring objections, I mean to apply this to trunk and branch later
today.  It's tested on the trunk; I'm running branch tests now.

-- 
zw               "Shouldn't a witch be eccentric?"
                 "I hope not. I've never been good at cackling."
                 	-- Reinder Dijkhuis, _Rogues of Clwyd-Rhan_

	* i386.md: Add two peepholes to clean up code generated by
	cmpstr* expanders.

===================================================================
Index: config/i386/i386.md
--- config/i386/i386.md	2001/05/09 14:03:39	1.269
+++ config/i386/i386.md	2001/05/16 17:38:47
@@ -15463,6 +15463,91 @@
   [(set_attr "type" "str")
    (set_attr "mode" "QI")
    (set_attr "prefix_rep" "1")])
+
+;; Peephole optimizations to clean up after cmpstr*.  This should be
+;; handled in combine, but it is not currently up to the task.
+;; When used for their truth value, the cmpstr* expanders generate
+;; code like this:
+;;
+;;   repz cmpsb
+;;   seta 	%al
+;;   setb 	%dl
+;;   cmpb 	%al, %dl
+;;   jcc	label
+;;
+;; The intermediate three instructions are unnecessary.
+
+;; This one handles cmpstr*_nz_1...
+(define_peephole2
+  [(parallel[
+     (set (reg:CC 17)
+	  (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
+		      (mem:BLK (match_operand 5 "register_operand" ""))))
+     (use (match_operand 6 "register_operand" ""))
+     (use (match_operand:SI 3 "immediate_operand" ""))
+     (use (reg:SI 19))
+     (clobber (match_operand 0 "register_operand" ""))
+     (clobber (match_operand 1 "register_operand" ""))
+     (clobber (match_operand 2 "register_operand" ""))])
+   (set (match_operand:QI 7 "register_operand" "")
+	(gtu:QI (reg:CC 17) (const_int 0)))
+   (set (match_operand:QI 8 "register_operand" "")
+	(ltu:QI (reg:CC 17) (const_int 0)))
+   (set (reg 17)
+	(compare (match_dup 7) (match_dup 8)))
+  ]
+  ""
+  [(parallel[
+     (set (reg:CC 17)
+	  (compare:CC (mem:BLK (match_dup 4))
+		      (mem:BLK (match_dup 5))))
+     (use (match_dup 6))
+     (use (match_dup 3))
+     (use (reg:SI 19))
+     (clobber (match_dup 0))
+     (clobber (match_dup 1))
+     (clobber (match_dup 2))])]
+  "")
+
+;; ...and this one handles cmpstr*_1.
+(define_peephole2
+  [(parallel[
+     (set (reg:CC 17)
+	  (if_then_else:CC (ne (match_operand 6 "register_operand" "")
+			       (const_int 0))
+	    (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
+		        (mem:BLK (match_operand 5 "register_operand" "")))
+	    (const_int 0)))
+     (use (match_operand:SI 3 "immediate_operand" ""))
+     (use (reg:CC 17))
+     (use (reg:SI 19))
+     (clobber (match_operand 0 "register_operand" ""))
+     (clobber (match_operand 1 "register_operand" ""))
+     (clobber (match_operand 2 "register_operand" ""))])
+   (set (match_operand:QI 7 "register_operand" "")
+	(gtu:QI (reg:CC 17) (const_int 0)))
+   (set (match_operand:QI 8 "register_operand" "")
+	(ltu:QI (reg:CC 17) (const_int 0)))
+   (set (reg 17)
+	(compare (match_dup 7) (match_dup 8)))
+  ]
+  ""
+  [(parallel[
+     (set (reg:CC 17)
+	  (if_then_else:CC (ne (match_dup 6)
+			       (const_int 0))
+	    (compare:CC (mem:BLK (match_dup 4))
+			(mem:BLK (match_dup 5)))
+	    (const_int 0)))
+     (use (match_dup 3))
+     (use (reg:CC 17))
+     (use (reg:SI 19))
+     (clobber (match_dup 0))
+     (clobber (match_dup 1))
+     (clobber (match_dup 2))])]
+  "")
+
+
 
 ;; Conditional move instructions.
 


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