1; RUN: opt < %s -simplifycfg -S | FileCheck %s
2;
3; rdar:13349374
4;
5; SimplifyCFG should not eliminate blocks with volatile stores.
6; Essentially, volatile needs to be backdoor that tells the optimizer
7; it can no longer use language standard as an excuse. The compiler
8; needs to expose the volatile access to the platform.
9;
10; CHECK-LABEL: @test(
11; CHECK: entry:
12; CHECK: @Trace
13; CHECK: while.body:
14; CHECK: store volatile
15; CHECK: end:
16target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
17
18define void @test(i8** nocapture %PeiServices) #0 {
19entry:
20  %call = tail call i32 (...) @Trace() #2
21  %tobool = icmp eq i32 %call, 0
22  br i1 %tobool, label %while.body, label %if.then
23
24if.then:                                          ; preds = %entry
25  %call1 = tail call i32 (...) @Trace() #2
26  br label %while.body
27
28while.body:                                       ; preds = %entry, %if.then, %while.body
29  %Addr.017 = phi i8* [ %incdec.ptr, %while.body ], [ null, %if.then ], [ null, %entry ]
30  %x.016 = phi i8 [ %inc, %while.body ], [ 0, %if.then ], [ 0, %entry ]
31  %inc = add i8 %x.016, 1
32  %incdec.ptr = getelementptr inbounds i8, i8* %Addr.017, i64 1
33  store volatile i8 %x.016, i8* %Addr.017, align 1
34  %0 = ptrtoint i8* %incdec.ptr to i64
35  %1 = trunc i64 %0 to i32
36  %cmp = icmp ult i32 %1, 4096
37  br i1 %cmp, label %while.body, label %end
38
39end:
40  ret void
41}
42declare i32 @Trace(...) #1
43
44attributes #0 = { nounwind ssp uwtable "fp-contract-model"="standard" "no-frame-pointer-elim" "no-frame-pointer-elim-non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
45attributes #1 = { "fp-contract-model"="standard" "no-frame-pointer-elim" "no-frame-pointer-elim-non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
46attributes #2 = { nounwind }
47
48!0 = !{i32 1039}
49