* [committed] Eliminate more comparisons on the H8 port
@ 2023-05-09 13:23 Jeff Law
0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-05-09 13:23 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 701 bytes --]
This patch fixes a minor code quality issue I found while testing LRA on
the H8. Specifically we have a peephole which converts a comparison of
a memory location against zero into a load + comparison which is
actually more efficient. This triggers when there are registers
available at the right point during peephole2.
If the load is not a mode dependent address we can actually do better by
realizing the load itself sets the proper flags and eliminate the
comparison. I may have expected this to happen when I wrote the
original peephole2 -- but cmpelim runs before peephole2, so clearly if
we want to eliminate the comparison we have to do it manually.
Committed to the trunk,
Jeff
[-- Attachment #2: P --]
[-- Type: text/plain, Size: 2312 bytes --]
commit 204303c81e82ddd01e7dc5a5a63719d476f9043c
Author: Jeff Law <jlaw@ventanamicro>
Date: Tue May 9 07:18:45 2023 -0600
Eliminate more comparisons on the H8 port
This patch fixes a minor code quality issue I found while testing LRA on the
H8. Specifically we have a peephole which converts a comparison of a memory
location against zero into a load + comparison which is actually more
efficient. This triggers when there are registers available at the right
point during peephole2.
If the load is not a mode dependent address we can actually do better by
realizing the load itself sets the proper flags and eliminate the comparison.
I may have expected this to happen when I wrote the original peephole2,
but cmpelim runs before peephole2, so clearly if we want to eliminate the
comparison we have to do it manually.
gcc/
* config/h8300/testcompare.md: Add peephole2 which uses a memory
load to set flags, thus eliminating a compare against zero.
diff --git a/gcc/config/h8300/testcompare.md b/gcc/config/h8300/testcompare.md
index 81dce1d0bc1..efa66d274c7 100644
--- a/gcc/config/h8300/testcompare.md
+++ b/gcc/config/h8300/testcompare.md
@@ -171,13 +171,25 @@ (define_insn "cmpsi"
(set_attr "length_table" "*,add")])
;; Convert a memory comparison to a move if there is a scratch register.
+;; This is preferred over the next as we can proactively avoid the
+;; comparison.
+(define_peephole2
+ [(match_scratch:QHSI 1 "r")
+ (set (reg:CC CC_REG)
+ (compare (match_operand:QHSI 0 "memory_operand" "")
+ (const_int 0)))]
+ "!mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE (operands[0]))"
+ [(parallel [(set (reg:CCZN CC_REG) (compare:CCZN (match_dup 0) (const_int 0)))
+ (set (match_dup 1) (match_dup 0))])])
+;; Similarly, but used when the memory reference is an autoinc address
+;; mode.
(define_peephole2
[(match_scratch:QHSI 1 "r")
(set (reg:CC CC_REG)
(compare (match_operand:QHSI 0 "memory_operand" "")
(const_int 0)))]
- ""
+ "mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE (operands[0]))"
[(parallel [(set (match_dup 1) (match_dup 0)) (clobber (reg:CC CC_REG))])
(set (reg:CC CC_REG) (compare:CC (match_dup 1) (const_int 0)))])
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-09 13:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09 13:23 [committed] Eliminate more comparisons on the H8 port Jeff 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).