From: Anton Korobeynikov Date: Sun, 26 Aug 2007 21:43:30 +0000 (+0000) Subject: Don't promote volatile loads/stores. This is needed (for example) to handle setjmp... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=9f528e628090ee0ffca35d4577c23b6544f9a119;p=oota-llvm.git Don't promote volatile loads/stores. This is needed (for example) to handle setjmp/longjmp properly. This fixes PR1520. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41461 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index a6fb8707d41..33489711388 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -63,14 +63,17 @@ bool llvm::isAllocaPromotable(const AllocaInst *AI) { // FIXME: If the memory unit is of pointer or integer type, we can permit // assignments to subsections of the memory unit. - // Only allow direct loads and stores... + // Only allow direct and non-volatile loads and stores... for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end(); UI != UE; ++UI) // Loop over all of the uses of the alloca - if (isa(*UI)) { - // noop + if (const LoadInst *LI = dyn_cast(*UI)) { + if (LI->isVolatile()) + return false; } else if (const StoreInst *SI = dyn_cast(*UI)) { if (SI->getOperand(0) == AI) return false; // Don't allow a store OF the AI, only INTO the AI. + if (SI->isVolatile()) + return false; } else { return false; // Not a load or store. } diff --git a/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll b/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll new file mode 100644 index 00000000000..579ed41c94c --- /dev/null +++ b/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll @@ -0,0 +1,47 @@ +; RUN: llvm-as < %s | opt -std-compile-opts | llvm-dis | grep volatile | count 3 +; PR1520 +; Don't promote volatile loads/stores. This is really needed to handle setjmp/lonjmp properly. + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32" +target triple = "i686-pc-linux-gnu" + %struct.__jmp_buf_tag = type { [6 x i32], i32, %struct.__sigset_t } + %struct.__sigset_t = type { [32 x i32] } +@j = external global [1 x %struct.__jmp_buf_tag] ; <[1 x %struct.__jmp_buf_tag]*> [#uses=1] + +define i32 @f() { +entry: + %retval = alloca i32, align 4 ; [#uses=2] + %v = alloca i32, align 4 ; [#uses=3] + %tmp = alloca i32, align 4 ; [#uses=3] + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + volatile store i32 0, i32* %v, align 4 + %tmp1 = call i32 @_setjmp( %struct.__jmp_buf_tag* getelementptr ([1 x %struct.__jmp_buf_tag]* @j, i32 0, i32 0) ) ; [#uses=1] + %tmp2 = icmp ne i32 %tmp1, 0 ; [#uses=1] + %tmp23 = zext i1 %tmp2 to i8 ; [#uses=1] + %toBool = icmp ne i8 %tmp23, 0 ; [#uses=1] + br i1 %toBool, label %bb, label %bb5 + +bb: ; preds = %entry + %tmp4 = volatile load i32* %v, align 4 ; [#uses=1] + store i32 %tmp4, i32* %tmp, align 4 + br label %bb6 + +bb5: ; preds = %entry + volatile store i32 1, i32* %v, align 4 + call void @g( ) + store i32 0, i32* %tmp, align 4 + br label %bb6 + +bb6: ; preds = %bb5, %bb + %tmp7 = load i32* %tmp, align 4 ; [#uses=1] + store i32 %tmp7, i32* %retval, align 4 + br label %return + +return: ; preds = %bb6 + %retval8 = load i32* %retval ; [#uses=1] + ret i32 %retval8 +} + +declare i32 @_setjmp(%struct.__jmp_buf_tag*) + +declare void @g()