[llvm] r320407 - [InstCombine] Fix PR35618: Instcombine hangs on single minmax load bitcast.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 13:16:17 PST 2017


The tests fail (opt asserts) on Windows:
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/8079

I've reverted in r320421.

On Mon, Dec 11, 2017 at 11:11 AM, Alexey Bataev via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: abataev
> Date: Mon Dec 11 11:11:16 2017
> New Revision: 320407
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320407&view=rev
> Log:
> [InstCombine] Fix PR35618: Instcombine hangs on single minmax load bitcast.
>
> Summary:
> If we have pattern `store (load(bitcast(select (cmp(V1, V2), &V1,
> &V2)))), bitcast)`, but the load is used in other instructions, it leads
> to looping in InstCombiner. Patch adds additional check that all users
> of the load instructions are stores and then replaces all uses of load
> instruction by the new one with new type.
>
> Reviewers: RKSimon, spatel, majnemer
>
> Subscribers: llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D41072
>
> Added:
>     llvm/trunk/test/Transforms/InstCombine/multiple-uses-
> load-bitcast-select.ll
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/
> InstCombineLoadStoreAlloca.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
> Transforms/InstCombine/InstCombineLoadStoreAlloca.
> cpp?rev=320407&r1=320406&r2=320407&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> Mon Dec 11 11:11:16 2017
> @@ -1344,9 +1344,24 @@ bool removeBitcastsFromLoadStoreOnMinMax
>    if (!isMinMaxWithLoads(LoadAddr))
>      return false;
>
> +  if (!all_of(LI->users(), [LI](User *U) {
> +        auto *SI = dyn_cast<StoreInst>(U);
> +        return SI && SI->getPointerOperand() != LI &&
> +               !SI->getPointerOperand()->isSwiftError();
> +      }))
> +    return false;
> +
> +  IC.Builder.SetInsertPoint(LI);
>    LoadInst *NewLI = combineLoadToNewType(
>        IC, *LI, LoadAddr->getType()->getPointerElementType());
> -  combineStoreToNewValue(IC, SI, NewLI);
> +  // Replace all the stores with stores of the newly loaded value.
> +  for (auto *UI : LI->users()) {
> +    auto *SI = cast<StoreInst>(UI);
> +    IC.Builder.SetInsertPoint(SI);
> +    combineStoreToNewValue(IC, *SI, NewLI);
> +    IC.eraseInstFromFunction(*SI);
> +  }
> +  IC.eraseInstFromFunction(*LI);
>    return true;
>  }
>
> @@ -1375,7 +1390,7 @@ Instruction *InstCombiner::visitStoreIns
>      return eraseInstFromFunction(SI);
>
>    if (removeBitcastsFromLoadStoreOnMinMax(*this, SI))
> -    return eraseInstFromFunction(SI);
> +    return nullptr;
>
>    // Replace GEP indices if possible.
>    if (Instruction *NewGEPI = replaceGEPIdxWithZero(*this, Ptr, SI)) {
>
> Added: llvm/trunk/test/Transforms/InstCombine/multiple-uses-
> load-bitcast-select.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> Transforms/InstCombine/multiple-uses-load-bitcast-
> select.ll?rev=320407&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
> (added)
> +++ llvm/trunk/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
> Mon Dec 11 11:11:16 2017
> @@ -0,0 +1,30 @@
> +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
> +; RUN: opt < %s -instcombine -S -data-layout="E-m:e-i1:8:16-
> i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" | FileCheck %s
> +
> +define void @PR35618(i64* %st1, double* %st2) {
> +; CHECK-LABEL: @PR35618(
> +; CHECK-NEXT:    [[Y1:%.*]] = alloca double, align 8
> +; CHECK-NEXT:    [[Z1:%.*]] = alloca double, align 8
> +; CHECK-NEXT:    [[LD1:%.*]] = load double, double* [[Y1]], align 8
> +; CHECK-NEXT:    [[LD2:%.*]] = load double, double* [[Z1]], align 8
> +; CHECK-NEXT:    [[TMP10:%.*]] = fcmp olt double [[LD1]], [[LD2]]
> +; CHECK-NEXT:    [[TMP121:%.*]] = select i1 [[TMP10]], double [[LD1]],
> double [[LD2]]
> +; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i64* [[ST1:%.*]] to double*
> +; CHECK-NEXT:    store double [[TMP121]], double* [[TMP1]], align 8
> +; CHECK-NEXT:    store double [[TMP121]], double* [[ST2:%.*]], align 8
> +; CHECK-NEXT:    ret void
> +;
> +  %y1 = alloca double
> +  %z1 = alloca double
> +  %ld1 = load double, double* %y1
> +  %ld2 = load double, double* %z1
> +  %tmp10 = fcmp olt double %ld1, %ld2
> +  %sel = select i1 %tmp10, double* %y1, double* %z1
> +  %tmp11 = bitcast double* %sel to i64*
> +  %tmp12 = load i64, i64* %tmp11
> +  store i64 %tmp12, i64* %st1
> +  %bc = bitcast double* %st2 to i64*
> +  store i64 %tmp12, i64* %bc
> +  ret void
> +}
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171211/4aef3c78/attachment.html>


More information about the llvm-commits mailing list