From: "Naveen H. S" <Naveen.S@kpitcummins.com>
To: Ian Lance Taylor <iant@google.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: RE: Problem with peephole optimizing the register
Date: Wed, 05 Oct 2011 06:22:00 -0000 [thread overview]
Message-ID: <5CD0E437A05A514A90A1B12527F33154176BAF75@KCHJEXMB02.kpit.com> (raw)
In-Reply-To: <mcrzkhgoh2k.fsf@coign.corp.google.com>
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Hi,
>> Show us the RTL and the define_peephole2.
Thanks for looking at the issue.
Please find attached the file tbit.txt which has complete information
of RTL pattern generated and defined peephole patterns.
>> From what you have described so far peep2_reg_dead_p ought to work.
To use far peep2_reg_dead_p; peephole2 patterns were defined.
far peep2_reg_dead_p masked the generation of tbit instruction completely.
Hence, tbit instructions were not at all generated in any instance.
>> Also, which version of gcc?
We are using gcc-4.5.1 version.
Thanks & Regards,
Naveen
[-- Attachment #2: tbit.txt --]
[-- Type: text/plain, Size: 8579 bytes --]
RTL Pattern without the peephole optimization
============================================================================================================================================================
#(insn 13 36 14 /home/Src/Components/FWU/Manager/FwuManager.c:1245 (set (reg:HI 7 r7 [orig:26 Fdi[0].Flags ] [26])
# (mem/s:HI (symbol_ref:SI ("Fdi") [flags 0x2] <var_decl 0xb7a5b3f4 Fdi>) [3 Fdi[0].Flags+0 S2 A16])) 70 {*movhi_short} (expr_list:REG_EQUIV (mem/s:HI (symbol_ref:SI ("Fdi") [flags 0x2] <var_decl 0xb7a5b3f4 Fdi>) [3 Fdi[0].Flags+0 S2 A16])
# (nil)))
loadw _Fdi@l, r7 # Fdi[0].Flags, Fdi[0].Flags # 13 *movhi_short/5 [length = 6]
#(insn 14 13 15 /home/Src/Components/FWU/Manager/FwuManager.c:1245 (set (reg:HI 7 r7 [25])
# (and:HI (reg:HI 7 r7 [orig:26 Fdi[0].Flags ] [26])
# (const_int 16384 [0x4000]))) 27 {andhi3} (nil))
andw $16384, r7 #, tmp25 # 14 andhi3/3 [length = 4]
#(jump_insn 15 14 16 /home/Src/Components/FWU/Manager/FwuManager.c:1245 (parallel [
# (set (pc)
# (if_then_else (ne (reg:HI 7 r7 [25])
# (const_int 0 [0x0]))
# (label_ref:SI 27)
# (pc)))
# (clobber (cc0))
# ]) 74 {branchnehi} (expr_list:REG_BR_PROB (const_int 7100 [0x1bbc])
# (nil))
# -> 27)
bne0w r7,.L9 # tmp25, # 15 branchnehi [length = 2]
============================================================================================================================================================
RTL Pattern after the peephole optimization
===============================================================================================================
#(insn 205 258 27 /home/Src/Components/FWU/Manager/FwuManager.c:1803 (parallel [
# (reg:HI 2 r2 [54])
# (reg/v:HI 0 r0 [orig:23 f ] [23])
# (const_int 8 [0x8])
# (ne (reg:HI 2 r2 [54])
# (const_int 0 [0x0]))
# (code_label 163 253 164 70 "" [5 uses])
# ]) 147 {cr16_call_value+13} (nil))
tbit $3,r0 #, f # 205 cr16_call_value+13 [length = 2]
bfs .L70 #,
RTL Pattern
#(insn 17 16 18 /home/Src/Components/FWU/Manager/FwuManager.c:1249 (set (reg:HI 3 r3)
# (const_int 16383 [0x3fff])) 70 {*movhi_short} (nil))
movw $16383, r3 #, # 17 *movhi_short/3 [length = 4]
#(insn 18 17 19 /home/Src/Components/FWU/Manager/FwuManager.c:1249 (set (reg:QI 2 r2)
# (reg:QI 7 r7 [25])) 69 {*movqi_short} (expr_list:REG_EQUAL (const_int 0 [0x0])
# (nil)))
movb r7, r2 # tmp25, # 18 *movqi_short/1 [length = 2]
================================================================================================================
Peephole pattern used to generate the tbit instruction and hence optmized code
====================================================================================
(define_peephole
[(set (match_operand:CR16IM 0 "register_operand" "")
(match_operand:CR16IM 1 "memory_operand" ""))
(set (match_dup 0)
(and:CR16IM (match_dup 0)
(match_operand 2 "const_int_operand" "v")))
(parallel [(set (pc)
(if_then_else (match_operator 3 "ordered_comparison_operator"
[(match_dup 0)
(const_int 0)])
(label_ref (match_operand 4 "" ""))
(pc)))
(clobber (cc0))])]
"TARGET_BIT_OPS && satisfies_constraint_v (operands[2])"
"tbit%t0\t$%s2,%1\;bf%o3\t%l4")
Extra Info
Constarint v allows (1, 2 ......... -> 8192, 16384)
Print operand 't' prints b, w, w on QI, HI and SI mode respectively
Print operand 's' prints bit position
Print operand 'o' prints c on EQ and s on NE operations
====================================================================================
Peephole2 pattern used to generate tbit instruction using far peep2_reg_dead_p
====================================================================================
(define_peephole2
[(set (match_operand:CR16IM 0 "register_operand" "")
(match_operand:CR16IM 1 "memory_operand" ""))
(set (match_dup 0)
(and:CR16IM (match_dup 0)
(match_operand 2 "const_int_operand" "v")))
(parallel [(set (pc)
(if_then_else (match_operator 3 "ordered_comparison_operator"
[(match_dup 0)
(const_int 0)])
(label_ref (match_operand 4 "" ""))
(pc)))
(clobber (cc0))])]
"TARGET_BIT_OPS && satisfies_constraint_v (operands[2])
&& far peep2_reg_dead_p (2, operands[0])"
[(set (match_dup 0)
(unspec [(match_dup 1)(match_dup 2)] UNSPEC_TBIT))
(set (match_dup 0)
(unspec [(match_operator 3 ""
[(match_dup 1)
(const_int 0)])
(label_ref (match_dup 4))
(match_dup 0)] UNSPEC_BRANCH))]
""
)
====================================================================================
UNSPEC instructions used in peephole2 patterns
====================================================================================
(define_insn "tbit"
[(set (match_operand 0 "" "")
(unspec [(match_operand 1 "" "m,i")(match_operand 2 "" "")] UNSPEC_TBIT))]
""
"@
tbit%t0\t$%s2,%1
tbit%t0\t$%s3,%c1"
[(set_attr "length" "2")]
)
(define_insn "branch_fs"
[(set (match_operand 0 "" "")
(unspec [(match_operator 1 ""
[(match_operand 2 "" "")
(const_int 0)])
(label_ref (match_operand 3 "" ""))
(match_operand 4 "" "")] UNSPEC_BRANCH))]
""
"bf%o1\t%l3"
[(set_attr "length" "2")]
)
====================================================================================
The generated assembly in the erraneous function
===================================================================
Generated assembler:
14019 _DeviceDataInit:
14022 0000 1E01 push ra
14023 0002 0701 push $1, r7
14026 0004 935A movw $-1, r3 #,
14027 0006 0258 movb $0, r2 #,
14028 0008 00C00000 bal (ra), _ClrFlags@c #
14031 000c 1100E0F0 tbitw $14,_Fdi@l # Fdi[0].Flags,, Fdi[0].Flags
14031 0000
14032 0012 8010 bfs .L9 #,
14034 0014 B35AFF3F movw $16383, r3 #,
14035 0018 7259 movb r7, r2 # tmp25, --------> Problem here r7 used without initialization
14036 001a 00C00000 bal (ra), _ClrFlags@c #
14038 001e 135A movw $1, r3 #,
14039 0020 7259 movb r7, r2 # tmp25, --------> Problem here r7 used without initialization
14040 0022 00C00000 bal (ra), _SetFlags@c #
14045 0026 0702 pop $1, r7
14046 0028 1E03 popret ra
RTL of the above problem
================================================================================================================
#(insn 13 36 16 /home/Src/Components/FWU/Manager/FwuManager.c:1245 (parallel [
# (reg:HI 7 r7 [orig:26 Fdi[0].Flags ] [26])
# (mem/s:HI (symbol_ref:SI ("Fdi") [flags 0x2] <var_decl 0xb7a873f4 Fdi>) [3 Fdi[0].Flags+0 S2 A16])
# (const_int 16384 [0x4000])
# (ne (reg:HI 7 r7 [25])
# (const_int 0 [0x0]))
# (code_label 27 38 28 9 "" [1 uses])
# ]) 136 {cr16_call_value+2} (expr_list:REG_EQUIV (mem/s:HI (symbol_ref:SI ("Fdi") [flags 0x2] <var_decl 0xb7a873f4 Fdi>) [3 Fdi[0].Flags+0 S2 A16])
# (nil)))
tbitw $14,_Fdi@l # Fdi[0].Flags,, Fdi[0].Flags # 13 cr16_call_value+2 [length = 6]
bfs .L9 #,
.loc 1 1249 0
#(insn 17 16 18 /home/Src/Components/FWU/Manager/FwuManager.c:1249 (set (reg:HI 3 r3)
# (const_int 16383 [0x3fff])) 70 {*movhi_short} (nil))
movw $16383, r3 #, # 17 *movhi_short/3 [length = 4]
#(insn 18 17 19 /home/Src/Components/FWU/Manager/FwuManager.c:1249 (set (reg:QI 2 r2)
# (reg:QI 7 r7 [25])) 69 {*movqi_short} (expr_list:REG_EQUAL (const_int 0 [0x0])
# (nil)))
movb r7, r2 # tmp25, # 18 *movqi_short/1 [length = 2] --------> Problem here r7 used without initialization
================================================================================================================
next prev parent reply other threads:[~2011-10-05 6:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-07 13:17 Problem of inline assembly for branch instruction Naveen H. S
2011-09-07 16:24 ` Ian Lance Taylor
2011-09-08 11:26 ` Naveen H. S
2011-10-04 14:09 ` Problem with peephole optimizing the register Naveen H. S
2011-10-04 16:30 ` Ian Lance Taylor
2011-10-05 6:22 ` Naveen H. S [this message]
2011-10-05 13:48 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5CD0E437A05A514A90A1B12527F33154176BAF75@KCHJEXMB02.kpit.com \
--to=naveen.s@kpitcummins.com \
--cc=gcc-help@gcc.gnu.org \
--cc=iant@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).