Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -954,16 +954,14 @@ // If there is an non-load/store instruction in the loop, we can't promote // it. if (const LoadInst *Load = dyn_cast(UI)) { - assert(!Load->isVolatile() && "AST broken"); - if (!Load->isSimple()) + if (!Load->isSimple() || !Load->isUnordered()) return Changed; } else if (const StoreInst *Store = dyn_cast(UI)) { // Stores *of* the pointer are not interesting, only stores *to* the // pointer. if (UI->getOperand(1) != ASIV) continue; - assert(!Store->isVolatile() && "AST broken"); - if (!Store->isSimple()) + if (!Store->isSimple() || !Store->isUnordered()) return Changed; // Don't sink stores from loops without dedicated block exits. Exits // containing indirect branches are not transformed by loop simplify, Index: test/Transforms/LICM/PR25628.ll =================================================================== --- /dev/null +++ test/Transforms/LICM/PR25628.ll @@ -0,0 +1,29 @@ +; RUN: opt -S -tbaa -licm < %s | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-NOT: %load2 = load i32*, i32** @b + +@b = external global i32*, align 8 + +define void @f(i1 %B, i1 %D) { +entry: + br i1 %B, label %for.body, label %for.end4 + +for.body: + store i32* null, i32** @b, align 8, !tbaa !0 + store i32 1, i32* null, align 8 + %load2 = load i32*, i32** @b, align 8, !tbaa !0 + %load3 = load volatile i32, i32* %load2, align 8, !tbaa !4 + br i1 %D, label %for.body, label %for.end4 + +for.end4: + ret void +} + +!0 = !{!1, !1, i64 0} +!1 = !{!"any pointer", !2, i64 0} +!2 = !{!"omnipotent char", !3, i64 0} +!3 = !{!"Simple C/C++ TBAA"} +!4 = !{!5, !5, i64 0} +!5 = !{!"int", !2, i64 0}