This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
reverse conditionnal jump
- From: BELBACHIR Selim <selim dot belbachir at fr dot thalesgroup dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 5 Jan 2012 14:49:47 +0100
- Subject: reverse conditionnal jump
Hi,
I'm still developping a new private target backend (gcc4.5.2) and I noticed something strange in the assembler generated for conditionnal jump.
The compiled C code source is :
void funct (int c) {
int a;
a = 7;
if (c < 0)
a = 4;
return a;
}
The assembler generated is :
[...]
mov 7,a
cmp 0,c #set the CC status
jmpif LT .L2 #conditionnal jump using CC status
.L1
ret a #return to callee
.L2
mov 4,a
jmp .L1 #unconditionnal jump
But, I was expecting only one jump as follow :
[...]
mov 7,a
cmp 0,c #set the CC status
jmpif GE .L1 #conditionnal jump using CC status
mov 4,a
.L1
ret a #return to callee
All comparison are available and I defined REVERSIBLE_CC_MODE(MODE) to 1.
I also have the following branch insn (and the cbranchsi4 expand)
(define_insn "*jmpif"
[(set (pc)
(if_then_else (match_operator 0 "comparison_operator"
[(reg:CC CCI_REG) (const_int 0)])
(label_ref (match_operand 1 "" ""))
(pc)))]
""
"jmpif %c0 %l1"
)
(define_insn "*reverse_jmpif"
[(set (pc)
(if_then_else (match_operator 0 "comparison_operator"
[(reg:CC CCI_REG) (const_int 0)])
(pc)
(label_ref (match_operand 1 "" ""))))]
""
"jmpif %C0 %l1"
)
How can I tell GCC to perform the best conditionnal jump by sometimes reversing the comparison ?
Regards,
Selim