Hi Dan,<div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">And finally gets optimised to this:<br>
<br>
        0x3741240: i1,ch = CopyFromReg 0x37241a8, 0x3741640 [ID=6]<br>
        0x3741340: i1 = Constant<-1> [ID=2]<br>
        0x3741940: ch = setne<br>
      0x3741740: i64 = setcc 0x3741240, 0x3741340, 0x3741940<br>
      0x3741540: ch = BasicBlock<else 0x373c230> [ID=3]<br>
    0x3741140: ch = brcond 0x37241a8, 0x3741740, 0x3741540 [ID=8]<br>
<br>
Which is invalid as setcc should always return an i1 type. I'm unsure as<br>
to whether this is coming from the -1 constant turning the setcc into an<br>
i64, or just the ISelLowering being set up incorrectly.<br>
<a href="http://llvm.org/docs/CodeGenerator.html#targetlowering" target="_blank">http://llvm.org/docs/CodeGenerator.html#targetlowering</a> does indicate<br>
that the return type of setcc operations should be specified in this<br>
class, though I'm not sure how this should be done.<br><br></blockquote><div><br></div><div>If you take a look at the TargetLowering class implementation (lib/CodeGen/SelectionDAG/TargetLowering.cpp), the virtual member function "getSetCCResultType()" is implemented as:</div>
<div><br></div><div>return PointerTy.SimpleTy;</div><div><br></div><div>So, the default action for the target independent code generator is to promote SetCC return types to the machine pointer type. Since this member function is virtual, you may try overriding getSetCCResultType().</div>
<div><br></div><div>But I think SetCC returning a type different of i1 is not invalid because you are in the lowering phase. In this phase, the code should comply to machine constraints (or, in other words, whatever the machine instruction selector can handle), and not the LLVM IR constraints. </div>
<div><br></div><div>-Rafael</div></div></div>