1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
4 @G = extern_weak global i32
7 ; Do not merge bb1 into the entry block, it might trap.
9 define i32 @admiral(i32 %a, i32 %b) {
10 ; CHECK-LABEL: @admiral(
11 ; CHECK-NEXT: [[C:%.*]] = icmp sle i32 %a, %b
12 ; CHECK-NEXT: br i1 [[C]], label %bb2, label %bb1
14 ; CHECK-NEXT: [[D:%.*]] = icmp sgt i32 sdiv (i32 -32768, i32 ptrtoint (i32* @G to i32)), 0
15 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[D]], i32 927, i32 42
16 ; CHECK-NEXT: br label %bb2
18 ; CHECK-NEXT: [[MERGE:%.*]] = phi i32 [ 42, %0 ], [ [[DOT]], %bb1 ]
19 ; CHECK-NEXT: ret i32 [[MERGE]]
21 %c = icmp sle i32 %a, %b
22 br i1 %c, label %bb2, label %bb1
24 %d = icmp sgt i32 sdiv (i32 -32768, i32 ptrtoint (i32* @G to i32)), 0
25 br i1 %d, label %bb6, label %bb2
32 define i32 @ackbar(i1 %c) {
33 ; CHECK-LABEL: @ackbar(
34 ; CHECK-NEXT: br i1 %c, label %bb5, label %bb6
36 ; CHECK-NEXT: [[DOT:%.*]] = select i1 icmp sgt (i32 sdiv (i32 32767, i32 ptrtoint (i32* @G to i32)), i32 0), i32 42, i32 927
37 ; CHECK-NEXT: br label %bb6
39 ; CHECK-NEXT: [[MERGE:%.*]] = phi i32 [ 42, %0 ], [ [[DOT]], %bb5 ]
40 ; CHECK-NEXT: ret i32 [[MERGE]]
42 br i1 %c, label %bb5, label %bb6
44 br i1 icmp sgt (i32 sdiv (i32 32767, i32 ptrtoint (i32* @G to i32)), i32 0), label %bb6, label %bb7
51 ; FP ops don't trap by default, so this is safe to hoist.
53 define i32 @tarp(i1 %c) {
56 ; CHECK-NEXT: [[DOT:%.*]] = select i1 fcmp oeq (float fdiv (float 3.000000e+00, float sitofp (i32 ptrtoint (i32* @G to i32) to float)), float 1.000000e+00), i32 42, i32 927
57 ; CHECK-NEXT: [[MERGE:%.*]] = select i1 %c, i32 [[DOT]], i32 42
58 ; CHECK-NEXT: ret i32 [[MERGE]]
60 br i1 %c, label %bb8, label %bb9
62 br i1 fcmp oeq (float fdiv (float 3.0, float sitofp (i32 ptrtoint (i32* @G to i32) to float)), float 1.0), label %bb9, label %bb10