<div dir="ltr">Your code seems fine. InstCombine can infinite loop if some other transform is reversing your transform. Can you send the whole patch and a test case?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Wed, Sep 13, 2017 at 10:01 AM, Haidl, Michael via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am working on PR34474 and try to add a new optimization to<br>
InstCombine. Like in other parts of the visitMul function I add a Shl<br>
through the IR builder and create a new BinaryOp which I return from<br>
visitMul. If I understand correctly the new BinaryOp returned from<br>
visitMul should replace the original Instruction in the Worklist.<br>
However, I end up in an infinite loop and the Instruction I try to<br>
replace gets scheduled again and again. What is wrong in my code?<br>
<br>
// Replace X * (2^C+/-1) with (X << C) -/+ X<br>
APInt Plus1 = *IVal + 1;<br>
APInt Minus1 = *IVal - 1;<br>
int isPow2 = Plus1.isPowerOf2() ? 1 : Minus1.isPowerOf2() ? -1 : 0;<br>
<br>
if (isPow2) {<br>
APInt &Pow2 = isPow2 > 0 ? Plus1 : Minus1;<br>
Value *Shl = Builder.CreateShl(Op0, Pow2.logBase2());<br>
return BinaryOperator::Create(isPow2 > 0 ? BinaryOperator::Sub :<br>
BinaryOperator::Add, Shl, Op0);<br>
}<br>
<br>
Thanks,<br>
Michael<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>