<div dir="ltr">Hey guys,<div><br></div><div>I've come across a bug when combining an AND of FCMPs. This bug occurs in my compiler as well as Clang built from trunk.</div><div><br></div><div style>A reduced test case is:</div>
<div style><br></div><div style><div>int foo( float a, double b ) {</div><div>  return (a == a) & (b == b);</div><div>}</div><div><br></div><div>and the error is:</div><div><br></div><div>Assertion failed: (getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to FCmp instruction are not of the same type!"), function FCmpInst, file [snip]/clang/llvm/include/llvm/IR/Instructions.h, line 1117.</div>
<div><br></div><div style><br></div><div style>We begin with a float "a" and double "b":<br></div><div style><br></div><div style>> (fcmp oeq a, a) & (fcmp oeq b, b) </div><div style><br></div><div style>
After canonicalization in InstCombine, we end up with the expression:</div><div style><br></div><div style>> (fcmp ord a, 0.0) & (fcmp ord b, 0.0)<br></div><div style><br></div><div style><div>The bug manifest is in InstCombiner::FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS), when trying to perform this transformation:</div>
<div><br></div><div>> (fcmp ord x, c) & (fcmp ord y, c)  -> (fcmp ord x, y)</div></div><div style><br></div><div style>This is all fine, except that the FCmpInst constructor in the IRBuilder requires that both operands to the new fcmp are the same type, which they are not.</div>
<div style><br></div><div style><br></div><div style>Any suggestions on a proper fix for this issue? Some initial thoughts...</div><div style><br></div><div style>1) The transformation could be suppressed if the operand types do not match.<br>
</div><div style><br></div><div style>2) Cast the smaller operand to the type of the larger operand. Are there any unforeseen implications here?</div><div style><br></div><div style>In any case, I suspect that there may be other transformations that need similar checks also. If there is a clear solution, I will be happy to submit a patch. Otherwise, I will file a Bug.</div>
<div style><br></div><div style>Thanks in advance,</div><div style>Cameron</div></div></div>