[LLVMdev] Code generation problem

John McCall rjmccall at apple.com
Mon Feb 8 14:07:32 PST 2010


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
yes:
  %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).

John.



More information about the llvm-dev mailing list