This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: Problem with peephole optimizing the register


"Naveen H. S" <Naveen.S@kpitcummins.com> writes:

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

This version is not checking whether operand[0] is dead.  These days we
generally recommend define_peephole2.  If you use define_peephole as in
this example, you need to use dead_or_set_p to check whether the
register is dead.


> 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))]
>   ""
> )

As far as I can see, this version won't compile--there is an extraneous
"far".  Also, you are passing 2 to peep2_reg_dead_p.  That is going to
check whether the register is live in the second insn of the peephole,
which it is: the second insn is the branch instruction, which tests the
register.  You need to pass 3 to peep2_reg_dead_p.

By the way, you don't need to explicitly check satisfies_constraint_v in
the peephold predicate, as that will be checked by the match_operand
constraint.

Ian


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