[LLVMdev] Code generation problem
russell.wallace at gmail.com
Mon Feb 8 14:10:42 PST 2010
Oh! Okay, thanks, I'll fix it up to do that then.
Any chance verifyFunction could be tightened up to catch this case?
I'm currently running all my generated code through it, and it passes
the i32 conditional without complaint.
On Mon, Feb 8, 2010 at 10:07 PM, John McCall <rjmccall at apple.com> wrote:
> On Feb 8, 2010, at 1:53 PM, Russell Wallace wrote:
>> I was testing my implementation of the usual ternary function just
>> now, and it's giving the wrong answer; I would attribute this to an
>> error in my parser/abstract syntax tree code, but looking at the
>> output, as far as I can see, the intermediate code is correct at the
>> point where I hand it to LLVM's JIT. Could someone look and see if I'm
>> doing something wrong, misunderstanding the semantics of the
>> intermediate code format or something?
> The condition on a branch instruction is not evaluated with C condition
> semantics. It must be of i1 type, i.e. either true or false. Your IR should
> (presumably) be more like:
> %c1 = icmp ne i32 1, i32 0
> br i1 %c1, label %yes, label %no
> %c2 = icmp ne i32 2, i32 0
> br i1 %c2, ....
> Also, if you are producing IR yourself, you should always be running the IR
> verification pass (at least in debug mode), which should catch structural
> problems like this (and many others).
More information about the llvm-dev