llvm.org GIT mirror llvm / 9f528e6
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 Anton Korobeynikov 12 years ago
2 changed file(s) with 53 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
6262 // FIXME: If the memory unit is of pointer or integer type, we can permit
6363 // assignments to subsections of the memory unit.
6464
65 // Only allow direct loads and stores...
65 // Only allow direct and non-volatile loads and stores...
6666 for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end();
6767 UI != UE; ++UI) // Loop over all of the uses of the alloca
68 if (isa(*UI)) {
69 // noop
68 if (const LoadInst *LI = dyn_cast(*UI)) {
69 if (LI->isVolatile())
70 return false;
7071 } else if (const StoreInst *SI = dyn_cast(*UI)) {
7172 if (SI->getOperand(0) == AI)
7273 return false; // Don't allow a store OF the AI, only INTO the AI.
74 if (SI->isVolatile())
75 return false;
7376 } else {
7477 return false; // Not a load or store.
7578 }
0 ; RUN: llvm-as < %s | opt -std-compile-opts | llvm-dis | grep volatile | count 3
1 ; PR1520
2 ; Don't promote volatile loads/stores. This is really needed to handle setjmp/lonjmp properly.
3
4 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"
5 target triple = "i686-pc-linux-gnu"
6 %struct.__jmp_buf_tag = type { [6 x i32], i32, %struct.__sigset_t }
7 %struct.__sigset_t = type { [32 x i32] }
8 @j = external global [1 x %struct.__jmp_buf_tag] ; <[1 x %struct.__jmp_buf_tag]*> [#uses=1]
9
10 define i32 @f() {
11 entry:
12 %retval = alloca i32, align 4 ; [#uses=2]
13 %v = alloca i32, align 4 ; [#uses=3]
14 %tmp = alloca i32, align 4 ; [#uses=3]
15 %"alloca point" = bitcast i32 0 to i32 ; [#uses=0]
16 volatile store i32 0, i32* %v, align 4
17 %tmp1 = call i32 @_setjmp( %struct.__jmp_buf_tag* getelementptr ([1 x %struct.__jmp_buf_tag]* @j, i32 0, i32 0) ) ; [#uses=1]
18 %tmp2 = icmp ne i32 %tmp1, 0 ; [#uses=1]
19 %tmp23 = zext i1 %tmp2 to i8 ; [#uses=1]
20 %toBool = icmp ne i8 %tmp23, 0 ; [#uses=1]
21 br i1 %toBool, label %bb, label %bb5
22
23 bb: ; preds = %entry
24 %tmp4 = volatile load i32* %v, align 4 ; [#uses=1]
25 store i32 %tmp4, i32* %tmp, align 4
26 br label %bb6
27
28 bb5: ; preds = %entry
29 volatile store i32 1, i32* %v, align 4
30 call void @g( )
31 store i32 0, i32* %tmp, align 4
32 br label %bb6
33
34 bb6: ; preds = %bb5, %bb
35 %tmp7 = load i32* %tmp, align 4 ; [#uses=1]
36 store i32 %tmp7, i32* %retval, align 4
37 br label %return
38
39 return: ; preds = %bb6
40 %retval8 = load i32* %retval ; [#uses=1]
41 ret i32 %retval8
42 }
43
44 declare i32 @_setjmp(%struct.__jmp_buf_tag*)
45
46 declare void @g()