This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Condition branch on least significant bit
- From: "Jan Hoogerbrugge" <hoogerbrugge at hotmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 20 Jun 2003 16:18:38 +0200
- Subject: Condition branch on least significant bit
- Bcc:
Hi,
Our target architecture, to which we are porting gcc, has the compare
instructions which produce a boolean and conditional jump instructions
which test the boolean and jump if the boolean is true. For code
generation I:
- wrote a `define_expand "cmpsi"' the collects the operands
- wrote a `define_expand "beq"' that generates
tmp = operand1 relop operand2
pc = (tmp != 0) ? label_ref : pc
- wrote a pattern that matches the conditional jump
(define_insn "branch_true"
[(set (pc) (if_then_else
(ne (match_operand:SI 1 "register_operand"
"r")
(const_int 0))
(label_ref (match_operand 0 "" ""))
(pc)))]
""
"cjump %1 %0")
The problem that we are facing is that the semantics of the cjump
instruction
does not corresponds to the semantics of the RTL pattern. The problem is
that
our cjump instruction does not test whether its first operand is zero or
non-zero. Instead it tests whether the least-significant bit of the first
operand is zero or one. With the code above, gcc translates
if(x != 0)
goto label
to
cjump x, label
while it should be
equal x, 0 -> tmp
cjump tmp, label
My question is how to achieve this? I changed the RTL pattern of the
branch_true define_insn into:
pc = (tmp & 1) != 0 ? label_ref : pc /* change pc if LSB == 1 */
and changed the `define_expand "beq"' accordingly so that RTL template
and the output template of branch_true correspond. However this does not
work. The compiler can't match the code generated by `define_expand "beq"'.
It seems that the `& 1' is optimised away and therefore branch_true will
not be matched.
Any idea how to deal with this problem?
Thanks,
Jan
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail