<div dir="ltr">Probably worth it. IIRC, this results in miscompiling some old versions of mplayer so it has actually been seen in the wild.<div><br></div><div><a class="GWVZpf gW" id="IloFPc-2" href="mailto:hans@chromium.org" tabindex="-1">+Hans Wennborg</a><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 21, 2017 at 11:34 AM Matthias Braun via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Would this be worthy of llvm-5.0 or is it too late/risky/uncommon a case?<br>
<br>
- Matthias<br>
<br>
> On Aug 18, 2017, at 11:56 PM, Chandler Carruth via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: chandlerc<br>
> Date: Fri Aug 18 23:56:11 2017<br>
> New Revision: 311229<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=311229&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=311229&view=rev</a><br>
> Log:<br>
> [Inliner] Fix a nasty bug when inlining a non-recursive trace of<br>
> a function into itself.<br>
><br>
> We tried to fix this before in r306495 but that got reverted as the<br>
> assert was actually hit.<br>
><br>
> This fixes the original bug (which we seem to have lost track of with<br>
> the revert) by blocking a second remapping when the function being<br>
> inlined is also the caller and the remapping could succeed but<br>
> erroneously.<br>
><br>
> The included test case would actually load from an inlined copy of the<br>
> alloca before this change, failing to load the stored value and<br>
> miscompiling.<br>
><br>
> Many thanks to Richard Smith for diagnosing a user miscompile to this<br>
> bug, and to Kyle for the first attempt and initial analysis and David Li<br>
> for remembering the issue and how to fix it and suggesting the patch.<br>
> I'm just stitching it together and landing it. =]<br>
><br>
> Modified:<br>
>    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br>
>    llvm/trunk/test/Transforms/Inline/recursive.ll<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=311229&r1=311228&r2=311229&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=311229&r1=311228&r2=311229&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Fri Aug 18 23:56:11 2017<br>
> @@ -341,8 +341,9 @@ void PruningFunctionCloner::CloneBlock(c<br>
>               SimplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {<br>
>         // On the off-chance that this simplifies to an instruction in the old<br>
>         // function, map it back into the new function.<br>
> -        if (Value *MappedV = VMap.lookup(V))<br>
> -          V = MappedV;<br>
> +        if (NewFunc != OldFunc)<br>
> +          if (Value *MappedV = VMap.lookup(V))<br>
> +            V = MappedV;<br>
><br>
>         if (!NewInst->mayHaveSideEffects()) {<br>
>           VMap[&*II] = V;<br>
><br>
> Modified: llvm/trunk/test/Transforms/Inline/recursive.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/recursive.ll?rev=311229&r1=311228&r2=311229&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/recursive.ll?rev=311229&r1=311228&r2=311229&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/Inline/recursive.ll (original)<br>
> +++ llvm/trunk/test/Transforms/Inline/recursive.ll Fri Aug 18 23:56:11 2017<br>
> @@ -40,3 +40,34 @@ declare void @bar(i8* %in)<br>
><br>
> declare i32 @foo(i32 %param)<br>
><br>
> +; Check that when inlining a non-recursive path into a function's own body that<br>
> +; we get the re-mapping of instructions correct.<br>
> +define i32 @test_recursive_inlining_remapping(i1 %init, i8* %addr) {<br>
> +; CHECK-LABEL: define i32 @test_recursive_inlining_remapping(<br>
> +bb:<br>
> +  %n = alloca i32<br>
> +  br i1 %init, label %store, label %load<br>
> +; CHECK-NOT:     alloca<br>
> +;<br>
> +; CHECK:         %[[N:.*]] = alloca i32<br>
> +; CHECK-NEXT:    br i1 %init,<br>
> +<br>
> +store:<br>
> +  store i32 0, i32* %n<br>
> +  %cast = bitcast i32* %n to i8*<br>
> +  %v = call i32 @test_recursive_inlining_remapping(i1 false, i8* %cast)<br>
> +  ret i32 %v<br>
> +; CHECK-NOT:     call<br>
> +;<br>
> +; CHECK:         store i32 0, i32* %[[N]]<br>
> +; CHECK-NEXT:    %[[CAST:.*]] = bitcast i32* %[[N]] to i8*<br>
> +; CHECK-NEXT:    %[[INLINED_LOAD:.*]] = load i32, i32* %[[N]]<br>
> +; CHECK-NEXT:    ret i32 %[[INLINED_LOAD]]<br>
> +;<br>
> +; CHECK-NOT:     call<br>
> +<br>
> +load:<br>
> +  %castback = bitcast i8* %addr to i32*<br>
> +  %n.load = load i32, i32* %castback<br>
> +  ret i32 %n.load<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>