1 ; RUN: opt < %s -O3 -S | FileCheck %s
2 ; See issue #55013 and PR #70845 for more details.
3 ; This test comes from the following C program, compiled with clang
5 ;; short vecreduce_smin_v2i16(int n, short* v)
8 ;; for (int i = 0; i < n; ++i)
9 ;; p = p > v[i] ? v[i] : p;
13 ;; short vecreduce_smax_v2i16(int n, short* v)
16 ;; for (int i = 0; i < n; ++i)
17 ;; p = p < v[i] ? v[i] : p;
21 define i16 @vecreduce_smin_v2i16(i32 %n, ptr %v) {
22 ; CHECK-LABEL: define range(i16 -32768, 1) i16 @vecreduce_smin_v2i16(
23 ; CHECK: @llvm.smin.v2i16
28 for.cond: ; preds = %for.inc, %entry
29 %p.0 = phi i16 [ 0, %entry ], [ %conv8, %for.inc ]
30 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
31 %cmp = icmp slt i32 %i.0, %n
32 br i1 %cmp, label %for.body, label %for.end
34 for.body: ; preds = %for.cond
35 %conv = sext i16 %p.0 to i32
36 %idxprom = sext i32 %i.0 to i64
37 %arrayidx = getelementptr inbounds i16, ptr %v, i64 %idxprom
38 %0 = load i16, ptr %arrayidx, align 2
39 %conv1 = sext i16 %0 to i32
40 %cmp2 = icmp sgt i32 %conv, %conv1
41 br i1 %cmp2, label %cond.true, label %cond.false
43 cond.true: ; preds = %for.body
44 %idxprom4 = sext i32 %i.0 to i64
45 %arrayidx5 = getelementptr inbounds i16, ptr %v, i64 %idxprom4
46 %1 = load i16, ptr %arrayidx5, align 2
47 %conv6 = sext i16 %1 to i32
50 cond.false: ; preds = %for.body
51 %conv7 = sext i16 %p.0 to i32
54 cond.end: ; preds = %cond.false, %cond.true
55 %cond = phi i32 [ %conv6, %cond.true ], [ %conv7, %cond.false ]
56 %conv8 = trunc i32 %cond to i16
59 for.inc: ; preds = %cond.end
60 %inc = add nsw i32 %i.0, 1
63 for.end: ; preds = %for.cond
67 define i16 @vecreduce_smax_v2i16(i32 %n, ptr %v) {
68 ; CHECK-LABEL: define range(i16 0, -32768) i16 @vecreduce_smax_v2i16(
69 ; CHECK: @llvm.smax.v2i16
74 for.cond: ; preds = %for.inc, %entry
75 %p.0 = phi i16 [ 0, %entry ], [ %conv8, %for.inc ]
76 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
77 %cmp = icmp slt i32 %i.0, %n
78 br i1 %cmp, label %for.body, label %for.end
80 for.body: ; preds = %for.cond
81 %conv = sext i16 %p.0 to i32
82 %idxprom = sext i32 %i.0 to i64
83 %arrayidx = getelementptr inbounds i16, ptr %v, i64 %idxprom
84 %0 = load i16, ptr %arrayidx, align 2
85 %conv1 = sext i16 %0 to i32
86 %cmp2 = icmp slt i32 %conv, %conv1
87 br i1 %cmp2, label %cond.true, label %cond.false
89 cond.true: ; preds = %for.body
90 %idxprom4 = sext i32 %i.0 to i64
91 %arrayidx5 = getelementptr inbounds i16, ptr %v, i64 %idxprom4
92 %1 = load i16, ptr %arrayidx5, align 2
93 %conv6 = sext i16 %1 to i32
96 cond.false: ; preds = %for.body
97 %conv7 = sext i16 %p.0 to i32
100 cond.end: ; preds = %cond.false, %cond.true
101 %cond = phi i32 [ %conv6, %cond.true ], [ %conv7, %cond.false ]
102 %conv8 = trunc i32 %cond to i16
105 for.inc: ; preds = %cond.end
106 %inc = add nsw i32 %i.0, 1
109 for.end: ; preds = %for.cond