[llvm] r371434 - [IfConversion] Correctly handle cases where analyzeBranch fails.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 00:30:20 PDT 2019


Meged to release_90 in r371490.

On Mon, Sep 9, 2019 at 8:27 PM Eli Friedman via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: efriedma
> Date: Mon Sep  9 11:29:27 2019
> New Revision: 371434
>
> URL: http://llvm.org/viewvc/llvm-project?rev=371434&view=rev
> Log:
> [IfConversion] Correctly handle cases where analyzeBranch fails.
>
> If analyzeBranch fails, on some targets, the out parameters point to
> some blocks in the function. But we can't use that information, so make
> sure to clear it out.  (In some places in IfConversion, we assume that
> any block with a TrueBB is analyzable.)
>
> The change to the testcase makes it trigger a bug on builds without this
> fix: IfConvertDiamond tries to perform a followup "merge" operation,
> which isn't legal, and we somehow end up with a branch to a deleted MBB.
> I'm not sure how this doesn't crash the compiler.
>
> Differential Revision: https://reviews.llvm.org/D67306
>
>
> Modified:
>     llvm/trunk/lib/CodeGen/IfConversion.cpp
>     llvm/trunk/test/CodeGen/ARM/ifcvt-diamond-unanalyzable-common.mir
>
> Modified: llvm/trunk/lib/CodeGen/IfConversion.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/IfConversion.cpp?rev=371434&r1=371433&r2=371434&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/IfConversion.cpp (original)
> +++ llvm/trunk/lib/CodeGen/IfConversion.cpp Mon Sep  9 11:29:27 2019
> @@ -912,6 +912,12 @@ void IfConverter::AnalyzeBranches(BBInfo
>    BBI.BrCond.clear();
>    BBI.IsBrAnalyzable =
>        !TII->analyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
> +  if (!BBI.IsBrAnalyzable) {
> +    BBI.TrueBB = nullptr;
> +    BBI.FalseBB = nullptr;
> +    BBI.BrCond.clear();
> +  }
> +
>    SmallVector<MachineOperand, 4> RevCond(BBI.BrCond.begin(), BBI.BrCond.end());
>    BBI.IsBrReversible = (RevCond.size() == 0) ||
>        !TII->reverseBranchCondition(RevCond);
>
> Modified: llvm/trunk/test/CodeGen/ARM/ifcvt-diamond-unanalyzable-common.mir
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/ifcvt-diamond-unanalyzable-common.mir?rev=371434&r1=371433&r2=371434&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/ARM/ifcvt-diamond-unanalyzable-common.mir (original)
> +++ llvm/trunk/test/CodeGen/ARM/ifcvt-diamond-unanalyzable-common.mir Mon Sep  9 11:29:27 2019
> @@ -1,4 +1,4 @@
> -# RUN: llc %s -o - -run-pass=if-converter | FileCheck %s
> +# RUN: llc %s -o - -run-pass=if-converter -verify-machineinstrs | FileCheck %s
>  # Make sure we correctly if-convert blocks containing an INLINEASM_BR.
>  # CHECK: t2CMPri killed renamable $r2, 34
>  # CHECK-NEXT: $r0 = t2MOVi 2, 1, $cpsr, $noreg
> @@ -48,9 +48,8 @@ body:             |
>      t2B %bb.3, 14, $noreg
>
>    bb.3:
> -    successors: %bb.4(0x80000000)
> -
>      INLINEASM &"", 1
> +    $sp = t2LDMIA_RET $sp, 14, $noreg, def $r4, def $pc
>
>    bb.4.l_yes (address-taken):
>      $sp = t2LDMIA_RET $sp, 14, $noreg, def $r4, def $pc
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list