1 ; RUN: llc -march=hexagon < %s | FileCheck %s
2 ; CHECK-LABEL: LBB0{{.*}}if.end
3 ; CHECK: r[[REG:[0-9]+]] = zxth
6 target triple = "hexagon"
8 @g0 = external constant [146 x i16], align 8
9 @g1 = external constant [0 x i16], align 2
11 define void @fred(i32* nocapture readonly %p0, i16 signext %p1, i16* nocapture %p2, i16 signext %p3, i16 signext %p4, i16 signext %p5) #0 {
13 %conv = sext i16 %p1 to i32
14 %0 = tail call i32 @llvm.hexagon.S2.asl.r.r.sat(i32 %conv, i32 1)
15 %1 = tail call i32 @llvm.hexagon.A2.sath(i32 %0)
16 %2 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 3, i32 %1)
17 %conv3 = sext i16 %p4 to i32
18 %cmp144 = icmp sgt i16 %p4, 0
19 br i1 %cmp144, label %for.body, label %for.end
21 for.body: ; preds = %entry, %for.body
22 %arrayidx.phi = phi i32* [ %arrayidx.inc, %for.body ], [ %p0, %entry ]
23 %i.0146.apmt = phi i32 [ %inc.apmt, %for.body ], [ 0, %entry ]
24 %L_temp1.0145 = phi i32 [ %5, %for.body ], [ 1, %entry ]
25 %3 = load i32, i32* %arrayidx.phi, align 4, !tbaa !1
26 %4 = tail call i32 @llvm.hexagon.A2.abssat(i32 %3)
27 %5 = tail call i32 @llvm.hexagon.A2.max(i32 %L_temp1.0145, i32 %4)
28 %inc.apmt = add nuw nsw i32 %i.0146.apmt, 1
29 %exitcond151 = icmp eq i32 %inc.apmt, %conv3
30 %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
31 br i1 %exitcond151, label %for.end, label %for.body, !llvm.loop !5
33 for.end: ; preds = %for.body, %entry
34 %L_temp1.0.lcssa = phi i32 [ 1, %entry ], [ %5, %for.body ]
35 %6 = tail call i32 @llvm.hexagon.S2.clbnorm(i32 %L_temp1.0.lcssa)
36 %arrayidx6 = getelementptr inbounds [146 x i16], [146 x i16]* @g0, i32 0, i32 %conv3
37 %7 = load i16, i16* %arrayidx6, align 2, !tbaa !7
38 %conv7 = sext i16 %7 to i32
39 %8 = tail call i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32 %6, i32 %conv7)
40 br i1 %cmp144, label %for.body14.lr.ph, label %for.end29
42 for.body14.lr.ph: ; preds = %for.end
43 %sext132 = shl i32 %8, 16
44 %conv17 = ashr exact i32 %sext132, 16
47 for.body14: ; preds = %for.body14, %for.body14.lr.ph
48 %arrayidx16.phi = phi i32* [ %p0, %for.body14.lr.ph ], [ %arrayidx16.inc, %for.body14 ]
49 %i.1143.apmt = phi i32 [ 0, %for.body14.lr.ph ], [ %inc28.apmt, %for.body14 ]
50 %L_temp.0142 = phi i32 [ 0, %for.body14.lr.ph ], [ %12, %for.body14 ]
51 %9 = load i32, i32* %arrayidx16.phi, align 4, !tbaa !1
52 %10 = tail call i32 @llvm.hexagon.S2.asl.r.r.sat(i32 %9, i32 %conv17)
53 %11 = tail call i32 @llvm.hexagon.A2.asrh(i32 %10)
54 %sext133 = shl i32 %11, 16
55 %conv23 = ashr exact i32 %sext133, 16
56 %12 = tail call i32 @llvm.hexagon.M2.mpy.acc.sat.ll.s0(i32 %L_temp.0142, i32 %conv23, i32 %conv23)
57 %inc28.apmt = add nuw nsw i32 %i.1143.apmt, 1
58 %exitcond = icmp eq i32 %inc28.apmt, %conv3
59 %arrayidx16.inc = getelementptr i32, i32* %arrayidx16.phi, i32 1
60 br i1 %exitcond, label %for.end29, label %for.body14
62 for.end29: ; preds = %for.body14, %for.end
63 %L_temp.0.lcssa = phi i32 [ 0, %for.end ], [ %12, %for.body14 ]
64 %13 = tail call i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32 %conv3, i32 1)
65 %cmp31 = icmp sgt i32 %13, 0
66 br i1 %cmp31, label %if.then, label %if.end
68 if.then: ; preds = %for.end29
69 %arrayidx34 = getelementptr inbounds [0 x i16], [0 x i16]* @g1, i32 0, i32 %conv3
70 %14 = load i16, i16* %arrayidx34, align 2, !tbaa !7
71 %cmp.i = icmp eq i32 %L_temp.0.lcssa, -2147483648
72 %cmp1.i = icmp eq i16 %14, -32768
73 %or.cond.i = and i1 %cmp.i, %cmp1.i
74 br i1 %or.cond.i, label %if.end, label %if.else.i
76 if.else.i: ; preds = %if.then
77 %conv3.i = sext i16 %14 to i32
78 %15 = tail call i32 @llvm.hexagon.M2.hmmpyl.s1(i32 %L_temp.0.lcssa, i32 %conv3.i) #2
79 %16 = tail call i64 @llvm.hexagon.M2.mpyd.ll.s1(i32 %conv3.i, i32 %L_temp.0.lcssa) #2
80 %conv5.i = trunc i64 %16 to i32
81 %phitmp = and i32 %conv5.i, 65535
84 if.end: ; preds = %if.else.i, %if.then, %for.end29
85 %L_temp.2 = phi i32 [ %L_temp.0.lcssa, %for.end29 ], [ %15, %if.else.i ], [ 2147483647, %if.then ]
86 %lsb.0 = phi i32 [ 0, %for.end29 ], [ %phitmp, %if.else.i ], [ 65535, %if.then ]
87 %sext = shl i32 %8, 16
88 %conv35 = ashr exact i32 %sext, 16
89 %17 = tail call i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32 %conv35, i32 16)
90 %18 = tail call i32 @llvm.hexagon.S2.asl.r.r.sat(i32 %17, i32 1)
91 %19 = tail call i32 @llvm.hexagon.A2.sath(i32 %18)
92 %20 = tail call i32 @llvm.hexagon.S2.clbnorm(i32 %L_temp.2)
93 %sext123 = shl i32 %20, 16
94 %conv38 = ashr exact i32 %sext123, 16
95 %sext124 = shl i32 %19, 16
96 %conv39 = ashr exact i32 %sext124, 16
97 %21 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv38, i32 %conv39)
98 %22 = tail call i32 @llvm.hexagon.S2.asl.r.r.sat(i32 %L_temp.2, i32 %conv38)
99 %23 = tail call i32 @llvm.hexagon.A2.zxth(i32 %lsb.0)
100 %24 = tail call i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32 16, i32 %conv38)
101 %25 = tail call i32 @llvm.hexagon.S2.lsr.r.r(i32 %23, i32 %24)
102 %sext125 = shl i32 %25, 16
103 %conv45 = ashr exact i32 %sext125, 16
104 %26 = tail call i32 @llvm.hexagon.A2.addsat(i32 %22, i32 %conv45)
105 %sext126 = shl i32 %2, 16
106 %conv46 = ashr exact i32 %sext126, 16
107 %sext127 = shl i32 %21, 16
108 %conv47 = ashr exact i32 %sext127, 16
109 %27 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv46, i32 %conv47)
110 %sext128 = shl i32 %27, 16
111 %conv49 = ashr exact i32 %sext128, 16
112 %cmp50 = icmp sgt i32 %sext128, 327679
113 %tobool = icmp eq i16 %p5, 0
114 %or.cond = or i1 %tobool, %cmp50
115 br i1 %or.cond, label %if.else68, label %if.then53
117 if.then53: ; preds = %if.end
118 %28 = tail call i32 @llvm.hexagon.S2.asl.r.r.sat(i32 %conv49, i32 1)
119 %29 = tail call i32 @llvm.hexagon.A2.sath(i32 %28)
120 %30 = tail call i32 @llvm.hexagon.A2.subsat(i32 %26, i32 1276901417)
121 %cmp56 = icmp slt i32 %30, 0
122 br i1 %cmp56, label %if.then58, label %if.else
124 if.then58: ; preds = %if.then53
125 %sext131 = shl i32 %29, 16
126 %conv59 = ashr exact i32 %sext131, 16
127 %31 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv59, i32 2)
130 if.else: ; preds = %if.then53
131 %32 = tail call i32 @llvm.hexagon.A2.subsat(i32 %26, i32 1805811301)
132 %cmp61 = icmp slt i32 %32, 0
133 br i1 %cmp61, label %if.then63, label %if.end80
135 if.then63: ; preds = %if.else
136 %sext130 = shl i32 %29, 16
137 %conv64 = ashr exact i32 %sext130, 16
138 %33 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv64, i32 1)
141 if.else68: ; preds = %if.end
142 %34 = tail call i32 @llvm.hexagon.A2.subsat(i32 %26, i32 1518500250)
143 %cmp69 = icmp slt i32 %34, 0
144 br i1 %cmp69, label %if.then71, label %if.end74
146 if.then71: ; preds = %if.else68
147 %35 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv49, i32 1)
150 if.end74: ; preds = %if.then71, %if.else68
151 %m.0.in = phi i32 [ %35, %if.then71 ], [ %27, %if.else68 ]
152 br i1 %tobool, label %if.end80, label %if.then76
154 if.then76: ; preds = %if.end74
155 %sext129 = shl i32 %m.0.in, 16
156 %conv77 = ashr exact i32 %sext129, 16
157 %36 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %conv77, i32 5)
160 if.end80: ; preds = %if.end74, %if.then76, %if.then58, %if.then63, %if.else
161 %m.1.in = phi i32 [ %31, %if.then58 ], [ %33, %if.then63 ], [ %29, %if.else ], [ %36, %if.then76 ], [ %m.0.in, %if.end74 ]
162 %m.1 = trunc i32 %m.1.in to i16
163 %cmp.i135 = icmp slt i16 %m.1, 0
164 %var_out.0.i136 = select i1 %cmp.i135, i16 0, i16 %m.1
165 %conv81 = sext i16 %p3 to i32
166 %37 = tail call i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32 %conv81, i32 1)
167 %conv82 = trunc i32 %37 to i16
168 %cmp.i134 = icmp sgt i16 %var_out.0.i136, %conv82
169 %var_out.0.i = select i1 %cmp.i134, i16 %conv82, i16 %var_out.0.i136
170 store i16 %var_out.0.i, i16* %p2, align 2, !tbaa !7
174 declare i32 @llvm.hexagon.A2.abssat(i32) #2
175 declare i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32, i32) #2
176 declare i32 @llvm.hexagon.A2.addsat(i32, i32) #2
177 declare i32 @llvm.hexagon.A2.asrh(i32) #2
178 declare i32 @llvm.hexagon.A2.max(i32, i32) #2
179 declare i32 @llvm.hexagon.A2.sath(i32) #2
180 declare i32 @llvm.hexagon.A2.subh.l16.sat.ll(i32, i32) #2
181 declare i32 @llvm.hexagon.A2.subsat(i32, i32) #2
182 declare i32 @llvm.hexagon.A2.zxth(i32) #2
183 declare i32 @llvm.hexagon.M2.hmmpyl.s1(i32, i32) #2
184 declare i32 @llvm.hexagon.M2.mpy.acc.sat.ll.s0(i32, i32, i32) #2
185 declare i32 @llvm.hexagon.S2.asl.r.r.sat(i32, i32) #2
186 declare i32 @llvm.hexagon.S2.asr.r.r.sat(i32, i32) #2
187 declare i32 @llvm.hexagon.S2.clbnorm(i32) #2
188 declare i32 @llvm.hexagon.S2.lsr.r.r(i32, i32) #2
189 declare i64 @llvm.hexagon.M2.mpyd.ll.s1(i32, i32) #2
190 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
191 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
193 attributes #0 = { norecurse nounwind "target-cpu"="hexagonv60" "target-features"="+hvx,,+hvx-length64b" "unsafe-fp-math"="false" "use-soft-float"="false" }
194 attributes #1 = { argmemonly nounwind }
195 attributes #2 = { nounwind readnone }
198 !1 = !{!2, !2, i64 0}
199 !2 = !{!"int", !3, i64 0}
200 !3 = !{!"omnipotent char", !4, i64 0}
201 !4 = !{!"Simple C/C++ TBAA"}
202 !5 = distinct !{!5, !6}
203 !6 = !{!"llvm.loop.threadify", i32 81508608}
204 !7 = !{!8, !8, i64 0}
205 !8 = !{!"short", !3, i64 0}
206 !9 = distinct !{!9, !10}
207 !10 = !{!"llvm.loop.threadify", i32 1441813}
208 !11 = distinct !{!11, !10}