On 8/14/14, 9:58 PM, Byungchan An wrote:> Hello. This is Byungchan An.
>
> I have a question on the llvm IR.
> I'm compiling grep and generate bitcode. Here, I found something weird
> such as the following.
>
>
> cond.true1536: ; preds =
> %while.body1531
> br *i1 false*, label %if.end1558, label %if.then1557, !dbg !6453
>
> Until now, what I examined is register value calculated as a result of
> icmp, rcmp, trunk, and phi.
> So, this makes me really confused... What type of that value is and
> how can this be generated? Any simple example that can lead to this
> bit code?
This looks like a conditional branch in which the condition of the
branch is the constant false. False is simply a boolean constant (note
the i1 type). C code similar to the above code would be:
if (0) {
...
} else {
...
}
As for why you're seeing it, I don't know. It could be that constant
propagation has been run but simplifycfg or adce has not. It could be
that the front-end figured out that the boolean condition is false (and
so it is there in the instruction) but the LLVM optimizations haven't
been run yet to change the conditional branch into an unconditional branch.
Remember that the condition to a conditional branch can be any LLVM
value with a type of i1. That includes instructions (e.g., icmp, load),
constants (e.g., true, false), constant expressions, and function arguments.
In any event, it is valid LLVM IR, and I suspect running the standard
set of O2 optimizations would change the branch into an unconditional
branch (I'm guessing either simplifycfg or adce would do the trick).
Regards,
John Criswell
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140815/6556ff42/attachment.html>