1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
6 ; SimplifyCFG should not eliminate blocks with volatile stores.
7 ; Essentially, volatile needs to be backdoor that tells the optimizer
8 ; it can no longer use language standard as an excuse. The compiler
9 ; needs to expose the volatile access to the platform.
11 target 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"
13 define void @test(ptr nocapture %PeiServices) #0 {
16 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (...) @Trace() #[[ATTR2:[0-9]+]]
17 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[CALL]], 0
18 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[WHILE_BODY:%.*]], label [[IF_THEN:%.*]]
20 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 (...) @Trace() #[[ATTR2]]
21 ; CHECK-NEXT: br label [[WHILE_BODY]]
23 ; CHECK-NEXT: [[ADDR_017:%.*]] = phi ptr [ [[INCDEC_PTR:%.*]], [[WHILE_BODY]] ], [ null, [[IF_THEN]] ], [ null, [[ENTRY:%.*]] ]
24 ; CHECK-NEXT: [[X_016:%.*]] = phi i8 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[IF_THEN]] ], [ 0, [[ENTRY]] ]
25 ; CHECK-NEXT: [[INC]] = add i8 [[X_016]], 1
26 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, ptr [[ADDR_017]], i64 1
27 ; CHECK-NEXT: store volatile i8 [[X_016]], ptr [[ADDR_017]], align 1
28 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[INCDEC_PTR]] to i64
29 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i32
30 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[TMP1]], 4096
31 ; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_BODY]], label [[END:%.*]]
33 ; CHECK-NEXT: ret void
36 %call = tail call i32 (...) @Trace() #2
37 %tobool = icmp eq i32 %call, 0
38 br i1 %tobool, label %while.body, label %if.then
40 if.then: ; preds = %entry
41 %call1 = tail call i32 (...) @Trace() #2
44 while.body: ; preds = %entry, %if.then, %while.body
45 %Addr.017 = phi ptr [ %incdec.ptr, %while.body ], [ null, %if.then ], [ null, %entry ]
46 %x.016 = phi i8 [ %inc, %while.body ], [ 0, %if.then ], [ 0, %entry ]
47 %inc = add i8 %x.016, 1
48 %incdec.ptr = getelementptr inbounds i8, ptr %Addr.017, i64 1
49 store volatile i8 %x.016, ptr %Addr.017, align 1
50 %0 = ptrtoint ptr %incdec.ptr to i64
51 %1 = trunc i64 %0 to i32
52 %cmp = icmp ult i32 %1, 4096
53 br i1 %cmp, label %while.body, label %end
58 declare i32 @Trace(...) #1
60 attributes #0 = { nounwind ssp uwtable "fp-contract-model"="standard" "frame-pointer"="non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
61 attributes #1 = { "fp-contract-model"="standard" "frame-pointer"="non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
62 attributes #2 = { nounwind }