Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -1267,8 +1267,8 @@ break; } - // Don't skip over loads or things that can modify memory. - if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory()) + // Don't skip over loads, throws or things that can modify memory. + if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory() || BBI->mayThrow()) break; } @@ -1391,8 +1391,8 @@ } // If we find something that may be using or overwriting the stored // value, or if we run out of instructions, we can't do the xform. - if (BBI->mayReadFromMemory() || BBI->mayWriteToMemory() || - BBI == OtherBB->begin()) + if (BBI->mayReadFromMemory() || BBI->mayThrow() || + BBI->mayWriteToMemory() || BBI == OtherBB->begin()) return false; } @@ -1401,7 +1401,7 @@ // StoreBB. for (BasicBlock::iterator I = StoreBB->begin(); &*I != &SI; ++I) { // FIXME: This should really be AA driven. - if (I->mayReadFromMemory() || I->mayWriteToMemory()) + if (I->mayReadFromMemory() || I->mayThrow() || I->mayWriteToMemory()) return false; } } Index: llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll +++ llvm/trunk/test/Transforms/InstCombine/readnone-maythrow.ll @@ -0,0 +1,34 @@ +; RUN: opt -S -instcombine < %s | FileCheck %s + +declare void @readnone_but_may_throw() readnone + +define void @f_0(i32* %ptr) { +; CHECK-LABEL: @f_0( +entry: +; CHECK: store i32 10, i32* %ptr +; CHECK-NEXT: call void @readnone_but_may_throw() +; CHECK-NEXT: store i32 20, i32* %ptr, align 4 +; CHECK: ret void + + store i32 10, i32* %ptr + call void @readnone_but_may_throw() + store i32 20, i32* %ptr + ret void +} + +define void @f_1(i1 %cond, i32* %ptr) { +; CHECK-LABEL: @f_1( +; CHECK: store i32 10, i32* %ptr +; CHECK-NEXT: call void @readnone_but_may_throw() + + store i32 10, i32* %ptr + call void @readnone_but_may_throw() + br i1 %cond, label %left, label %merge + +left: + store i32 20, i32* %ptr + br label %merge + +merge: + ret void +}