1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -simplifycfg -mtriple=thumbv8.1m.main -mattr=+mve -S %s -o - | FileCheck %s --check-prefix=CHECK-MVE
3; RUN: opt -simplifycfg -mtriple=thumbv8.1m.main -S %s -o - | FileCheck %s --check-prefix=CHECK-NOMVE
4
5define i32 @speculate_vector_extract(i32 %d, <4 x i32> %v) {
6; CHECK-MVE-LABEL: @speculate_vector_extract(
7; CHECK-MVE-NEXT:  entry:
8; CHECK-MVE-NEXT:    [[CONV:%.*]] = insertelement <4 x i32> undef, i32 [[D:%.*]], i32 0
9; CHECK-MVE-NEXT:    [[CONV2:%.*]] = insertelement <4 x i32> [[CONV]], i32 [[D]], i32 1
10; CHECK-MVE-NEXT:    [[CONV3:%.*]] = insertelement <4 x i32> [[CONV2]], i32 [[D]], i32 2
11; CHECK-MVE-NEXT:    [[CONV4:%.*]] = insertelement <4 x i32> [[CONV3]], i32 [[D]], i32 3
12; CHECK-MVE-NEXT:    [[TMP6:%.*]] = add nsw <4 x i32> [[CONV4]], <i32 0, i32 -1, i32 -2, i32 -3>
13; CHECK-MVE-NEXT:    [[CMP:%.*]] = icmp eq <4 x i32> [[TMP6]], zeroinitializer
14; CHECK-MVE-NEXT:    [[CMP_EXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
15; CHECK-MVE-NEXT:    [[TMP8:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 0
16; CHECK-MVE-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[TMP8]], 0
17; CHECK-MVE-NEXT:    br i1 [[TOBOOL]], label [[COND_ELSE:%.*]], label [[COND_THEN:%.*]]
18; CHECK-MVE:       cond.then:
19; CHECK-MVE-NEXT:    [[TMP10:%.*]] = extractelement <4 x i32> [[V:%.*]], i32 0
20; CHECK-MVE-NEXT:    br label [[COND_END:%.*]]
21; CHECK-MVE:       cond.else:
22; CHECK-MVE-NEXT:    [[TMP12:%.*]] = extractelement <4 x i32> [[V]], i32 3
23; CHECK-MVE-NEXT:    br label [[COND_END]]
24; CHECK-MVE:       cond.end:
25; CHECK-MVE-NEXT:    [[COND:%.*]] = phi i32 [ [[TMP10]], [[COND_THEN]] ], [ [[TMP12]], [[COND_ELSE]] ]
26; CHECK-MVE-NEXT:    [[TMP14:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 1
27; CHECK-MVE-NEXT:    [[TOBOOL15:%.*]] = icmp eq i32 [[TMP14]], 0
28; CHECK-MVE-NEXT:    [[TMP20:%.*]] = extractelement <4 x i32> [[V]], i32 1
29; CHECK-MVE-NEXT:    [[COND22:%.*]] = select i1 [[TOBOOL15]], i32 [[COND]], i32 [[TMP20]]
30; CHECK-MVE-NEXT:    [[TMP24:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 2
31; CHECK-MVE-NEXT:    [[TOBOOL25:%.*]] = icmp eq i32 [[TMP24]], 0
32; CHECK-MVE-NEXT:    [[TMP30:%.*]] = extractelement <4 x i32> [[V]], i32 2
33; CHECK-MVE-NEXT:    [[COND32:%.*]] = select i1 [[TOBOOL25]], i32 [[COND22]], i32 [[TMP30]]
34; CHECK-MVE-NEXT:    ret i32 [[COND32]]
35;
36; CHECK-NOMVE-LABEL: @speculate_vector_extract(
37; CHECK-NOMVE-NEXT:  entry:
38; CHECK-NOMVE-NEXT:    [[CONV:%.*]] = insertelement <4 x i32> undef, i32 [[D:%.*]], i32 0
39; CHECK-NOMVE-NEXT:    [[CONV2:%.*]] = insertelement <4 x i32> [[CONV]], i32 [[D]], i32 1
40; CHECK-NOMVE-NEXT:    [[CONV3:%.*]] = insertelement <4 x i32> [[CONV2]], i32 [[D]], i32 2
41; CHECK-NOMVE-NEXT:    [[CONV4:%.*]] = insertelement <4 x i32> [[CONV3]], i32 [[D]], i32 3
42; CHECK-NOMVE-NEXT:    [[TMP6:%.*]] = add nsw <4 x i32> [[CONV4]], <i32 0, i32 -1, i32 -2, i32 -3>
43; CHECK-NOMVE-NEXT:    [[CMP:%.*]] = icmp eq <4 x i32> [[TMP6]], zeroinitializer
44; CHECK-NOMVE-NEXT:    [[CMP_EXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
45; CHECK-NOMVE-NEXT:    [[TMP8:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 0
46; CHECK-NOMVE-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[TMP8]], 0
47; CHECK-NOMVE-NEXT:    [[TMP10:%.*]] = extractelement <4 x i32> [[V:%.*]], i32 0
48; CHECK-NOMVE-NEXT:    [[TMP12:%.*]] = extractelement <4 x i32> [[V]], i32 3
49; CHECK-NOMVE-NEXT:    [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[TMP12]], i32 [[TMP10]]
50; CHECK-NOMVE-NEXT:    [[TMP14:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 1
51; CHECK-NOMVE-NEXT:    [[TOBOOL15:%.*]] = icmp eq i32 [[TMP14]], 0
52; CHECK-NOMVE-NEXT:    [[TMP20:%.*]] = extractelement <4 x i32> [[V]], i32 1
53; CHECK-NOMVE-NEXT:    [[COND22:%.*]] = select i1 [[TOBOOL15]], i32 [[COND]], i32 [[TMP20]]
54; CHECK-NOMVE-NEXT:    [[TMP24:%.*]] = extractelement <4 x i32> [[CMP_EXT]], i32 2
55; CHECK-NOMVE-NEXT:    [[TOBOOL25:%.*]] = icmp eq i32 [[TMP24]], 0
56; CHECK-NOMVE-NEXT:    [[TMP30:%.*]] = extractelement <4 x i32> [[V]], i32 2
57; CHECK-NOMVE-NEXT:    [[COND32:%.*]] = select i1 [[TOBOOL25]], i32 [[COND22]], i32 [[TMP30]]
58; CHECK-NOMVE-NEXT:    ret i32 [[COND32]]
59;
60entry:
61  %conv = insertelement <4 x i32> undef, i32 %d, i32 0
62  %conv2 = insertelement <4 x i32> %conv, i32 %d, i32 1
63  %conv3 = insertelement <4 x i32> %conv2, i32 %d, i32 2
64  %conv4 = insertelement <4 x i32> %conv3, i32 %d, i32 3
65  %tmp6 = add nsw <4 x i32> %conv4, <i32 0, i32 -1, i32 -2, i32 -3>
66  %cmp = icmp eq <4 x i32> %tmp6, zeroinitializer
67  %cmp.ext = sext <4 x i1> %cmp to <4 x i32>
68  %tmp8 = extractelement <4 x i32> %cmp.ext, i32 0
69  %tobool = icmp eq i32 %tmp8, 0
70  br i1 %tobool, label %cond.else, label %cond.then
71
72return:                                           ; preds = %cond.end28
73  ret i32 %cond32
74
75cond.then:                                        ; preds = %entry
76  %tmp10 = extractelement <4 x i32> %v, i32 0
77  br label %cond.end
78
79cond.else:                                        ; preds = %entry
80  %tmp12 = extractelement <4 x i32> %v, i32 3
81  br label %cond.end
82
83cond.end:                                         ; preds = %cond.else, %cond.then
84  %cond = phi i32 [ %tmp10, %cond.then ], [ %tmp12, %cond.else ]
85  %tmp14 = extractelement <4 x i32> %cmp.ext, i32 1
86  %tobool15 = icmp eq i32 %tmp14, 0
87  br i1 %tobool15, label %cond.else17, label %cond.then16
88
89cond.then16:                                      ; preds = %cond.end
90  %tmp20 = extractelement <4 x i32> %v, i32 1
91  br label %cond.end18
92
93cond.else17:                                      ; preds = %cond.end
94  br label %cond.end18
95
96cond.end18:                                       ; preds = %cond.else17, %cond.then16
97  %cond22 = phi i32 [ %tmp20, %cond.then16 ], [ %cond, %cond.else17 ]
98  %tmp24 = extractelement <4 x i32> %cmp.ext, i32 2
99  %tobool25 = icmp eq i32 %tmp24, 0
100  br i1 %tobool25, label %cond.else27, label %cond.then26
101
102cond.then26:                                      ; preds = %cond.end18
103  %tmp30 = extractelement <4 x i32> %v, i32 2
104  br label %cond.end28
105
106cond.else27:                                      ; preds = %cond.end18
107  br label %cond.end28
108
109cond.end28:                                       ; preds = %cond.else27, %cond.then26
110  %cond32 = phi i32 [ %tmp30, %cond.then26 ], [ %cond22, %cond.else27 ]
111  br label %return
112}
113