Simplifying boolean expressions

Suppose I have a code like this:

       %tmp.aux = cast bool %tmp.24 to int
        %tmp.x = xor int %tmp.aux, 1 ; negates tmp.24
        %tmp.xx = cast int %tmp.x to bool
        %tmp.y = or bool %tmp.xx, %tmp.24 ; will be always true
        br bool %tmp.y, label %next6, label %next7

Is there an optimization in LLVM that will recognize that %tmp.y is always
true, and replace the entire basic block with unconditional jump?

I've tried running 'opt' on the attached file, but did not get the desired

The full story is that I'll be generating code like above, and while I
probably can detect such redundant situation, I was hoping I can save myself
some work, and just run LLVM optimizer at the produced code.


my_test.ll (964 Bytes)

I will enhance the -instcombine pass to do this, hopefully today.


Actually, the -instcombine pass already does this. Please try it out and let me know if it doesn't do what you want.


It does work! For some reason, I was assuming that running 'opt' without
arguments would run some "reasonable" set of optimizations, while in reality,
it does not run any.


I was afraid you were doing "opt < file.bc > out.bc" but I assumed that
you were actually using some switches with opt. :slight_smile:

Yes, without any command-line switches it's a noop. If you're looking
for the "standard" optimizations, you want to use gccas and/or gccld.

Actually, that's not exactly true. opt always runs the verify pass to
verify that the constructed module is sane. That pass, however, does no