xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/volatile-phioper.ll (revision e87aa9206606064fa3e9cd5a8c097a542ff0d559)
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
3;
4; rdar:13349374
5;
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.
10
11target 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"
12
13define void @test(ptr nocapture %PeiServices) #0 {
14; CHECK-LABEL: @test(
15; CHECK-NEXT:  entry:
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:%.*]]
19; CHECK:       if.then:
20; CHECK-NEXT:    [[CALL1:%.*]] = tail call i32 (...) @Trace() #[[ATTR2]]
21; CHECK-NEXT:    br label [[WHILE_BODY]]
22; CHECK:       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:%.*]]
32; CHECK:       end:
33; CHECK-NEXT:    ret void
34;
35entry:
36  %call = tail call i32 (...) @Trace() #2
37  %tobool = icmp eq i32 %call, 0
38  br i1 %tobool, label %while.body, label %if.then
39
40if.then:                                          ; preds = %entry
41  %call1 = tail call i32 (...) @Trace() #2
42  br label %while.body
43
44while.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
54
55end:
56  ret void
57}
58declare i32 @Trace(...) #1
59
60attributes #0 = { nounwind ssp uwtable "fp-contract-model"="standard" "frame-pointer"="non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
61attributes #1 = { "fp-contract-model"="standard" "frame-pointer"="non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
62attributes #2 = { nounwind }
63
64!0 = !{i32 1039}
65