[LLVMdev] is createCFGSimplificationPass unused?

Andrew Lenharth andrewl at lenharth.org
Thu Nov 2 19:34:55 PST 2006


On 11/2/06, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> It looks like createCFGSimplificationPass was disabled on 2006/09/04.
> This causes some problems for architectures that use conditional moves
> to implement select (alpha and ARM). For example, on 2006/09/03 a "if
> (a) return 0; else return 1;" compiled to

This is not because of how it handles select.  For example:

int %foo(int %x) {
%b = seteq int %x, 5
%r = select bool %b, int 3, int 7
ret int %r
}

int %bar(int %x) {
%b = seteq int %x, 5
br bool %b, label %t, label %f
t:
ret int 1
f:
ret int 2
}

compiles to:
foo:
        lda $0,3($31)
        zapnot $16,15,$1
        cmpeq $1,5,$1
        cmoveq $1,7,$0
        ret $31,($26),1
bar:
        zapnot $16,15,$0
        cmpeq $0,5,$0
        beq $0,$BB2_2   #f
$BB2_1: #t
        lda $0,1($31)
        ret $31,($26),1
$BB2_2: #f
        lda $0,2($31)
        ret $31,($26),1

Which is not a problem with the instruction selector's use of cmov.
It is that the IR is using a branch not a select.  SimplifyCFG was
creating selects in the IR, which instruction select to cmovs.  I
guess the question is is SimplifyCFG not run by default?  It seems it
should be at the end of normal optimization chain, as it should be
much easier to lower selects to branches and optimize that (for those
targets that don't use cmov) than try to raise branches to selects at
isel time (for those that do use cmov).

Andrew




More information about the llvm-dev mailing list