[LLVMdev] Helping the optimizer along (__assume)

Edward Lee eslee3 at uiuc.edu
Thu Oct 23 13:06:36 PDT 2008


On Thu, Oct 23, 2008 at 10:36 AM, Mike Stump <mrs at apple.com> wrote:
> On Oct 22, 2008, at 5:36 PM, Gordon Henriksen wrote:
>>       %cond = i1 ...
>>       br i1 %cond, label %always, label %never
>> never:
>>       unreachable
>> always:
> The thing I don't like about this, is that this has conditional
> branches all over the place, which break up basic blocks
I've been playing around with something similar to this except the
never block actually can be reached but calls a new intrinsic
@llvm.abort() followed by an unreachable.

In my case, I'm converting branches into asserts and moving the branch
for the assert around to create bigger basic blocks. If I make sure to
use the same "never" block with the abort() call, -simplifycfg will
combine the assert conditions by ANDing them together. A later pass to
-instcombine can get rid of redundant checks.

Additionally because I've got plain branches in the IR, -predsimplify
automatically handles code simplification without modifications.

So in regards to a generic assert/assume instruction, I would imagine
something like |assert i1 %cond, label %notTrue|. So assume would
provide a "never" block that is unreachable as the label where I could
provide "abort" block as the label. (The reason why it wouldn't be an
intrinsic is that intrinsics can't take labels.)

Ed



More information about the llvm-dev mailing list