xref: /aosp_15_r20/external/llvm/test/Transforms/SimplifyCFG/volatile-phioper.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -simplifycfg -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker;
3*9880d681SAndroid Build Coastguard Worker; rdar:13349374
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker; SimplifyCFG should not eliminate blocks with volatile stores.
6*9880d681SAndroid Build Coastguard Worker; Essentially, volatile needs to be backdoor that tells the optimizer
7*9880d681SAndroid Build Coastguard Worker; it can no longer use language standard as an excuse. The compiler
8*9880d681SAndroid Build Coastguard Worker; needs to expose the volatile access to the platform.
9*9880d681SAndroid Build Coastguard Worker;
10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test(
11*9880d681SAndroid Build Coastguard Worker; CHECK: entry:
12*9880d681SAndroid Build Coastguard Worker; CHECK: @Trace
13*9880d681SAndroid Build Coastguard Worker; CHECK: while.body:
14*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile
15*9880d681SAndroid Build Coastguard Worker; CHECK: end:
16*9880d681SAndroid Build Coastguard Workertarget 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*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Workerdefine void @test(i8** nocapture %PeiServices) #0 {
19*9880d681SAndroid Build Coastguard Workerentry:
20*9880d681SAndroid Build Coastguard Worker  %call = tail call i32 (...) @Trace() #2
21*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i32 %call, 0
22*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %while.body, label %if.then
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
25*9880d681SAndroid Build Coastguard Worker  %call1 = tail call i32 (...) @Trace() #2
26*9880d681SAndroid Build Coastguard Worker  br label %while.body
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Workerwhile.body:                                       ; preds = %entry, %if.then, %while.body
29*9880d681SAndroid Build Coastguard Worker  %Addr.017 = phi i8* [ %incdec.ptr, %while.body ], [ null, %if.then ], [ null, %entry ]
30*9880d681SAndroid Build Coastguard Worker  %x.016 = phi i8 [ %inc, %while.body ], [ 0, %if.then ], [ 0, %entry ]
31*9880d681SAndroid Build Coastguard Worker  %inc = add i8 %x.016, 1
32*9880d681SAndroid Build Coastguard Worker  %incdec.ptr = getelementptr inbounds i8, i8* %Addr.017, i64 1
33*9880d681SAndroid Build Coastguard Worker  store volatile i8 %x.016, i8* %Addr.017, align 1
34*9880d681SAndroid Build Coastguard Worker  %0 = ptrtoint i8* %incdec.ptr to i64
35*9880d681SAndroid Build Coastguard Worker  %1 = trunc i64 %0 to i32
36*9880d681SAndroid Build Coastguard Worker  %cmp = icmp ult i32 %1, 4096
37*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %while.body, label %end
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Workerend:
40*9880d681SAndroid Build Coastguard Worker  ret void
41*9880d681SAndroid Build Coastguard Worker}
42*9880d681SAndroid Build Coastguard Workerdeclare i32 @Trace(...) #1
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Workerattributes #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" }
45*9880d681SAndroid Build Coastguard Workerattributes #1 = { "fp-contract-model"="standard" "no-frame-pointer-elim" "no-frame-pointer-elim-non-leaf" "relocation-model"="pic" "ssp-buffers-size"="8" }
46*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind }
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker!0 = !{i32 1039}
49