blob: c366d059d3347b532040c48ec194bb68ea3e47f7 [file] [log] [blame]
Andrew Tricka0a5ca02013-03-07 01:03:35 +00001; 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;
Stephen Linc1c7a132013-07-14 01:42:54 +000010; CHECK-LABEL: @test(
Andrew Tricka0a5ca02013-03-07 01:03:35 +000011; 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:
David Blaikie23af6482015-04-16 23:24:18 +000020 %call = tail call i32 (...) @Trace() #2
Andrew Tricka0a5ca02013-03-07 01:03:35 +000021 %tobool = icmp eq i32 %call, 0
22 br i1 %tobool, label %while.body, label %if.then
23
24if.then: ; preds = %entry
David Blaikie23af6482015-04-16 23:24:18 +000025 %call1 = tail call i32 (...) @Trace() #2
Andrew Tricka0a5ca02013-03-07 01:03:35 +000026 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
David Blaikie79e6c742015-02-27 19:29:02 +000032 %incdec.ptr = getelementptr inbounds i8, i8* %Addr.017, i64 1
Andrew Tricka0a5ca02013-03-07 01:03:35 +000033 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
Bill Wendlinga5c536e2013-08-01 21:42:05 +000044attributes #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" }
Andrew Tricka0a5ca02013-03-07 01:03:35 +000046attributes #2 = { nounwind }
47
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000048!0 = !{i32 1039}