[LLVMdev] Helping the optimizer along (__assume)
Chris Lattner
clattner at apple.com
Wed Oct 22 23:46:04 PDT 2008
On Oct 22, 2008, at 10:45 PM, Duncan Sands wrote:
>> Can't you implement __builtin_assume(cond) to codegen to something
>> like:
>>
>> %cond = i1 ...
>> br i1 %cond, label %always, label %never
>> never:
>> unreachable
>> always:
>
> The code generators will remove the branch to %never.
> I already tried this :) What would work is to define
> an llvm.abort intrinsic, and do:
>
> %cond = i1 ...
> br i1 %cond, label %always, label %never
> never:
> call void @llvm.abort()
> unreachable
>
> At codegen time @llvm.abort() can be lowered to
> nothing at all. I'm not saying that this is my
> favorite solution, but it is simple.
How is this different than just branching to unreachable? Branching
to unreachable says that "this condition is true or else the program
has undefined behavior". This means that the condition must be true :)
-Chris
More information about the llvm-dev
mailing list