1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -mtriple=x86_64-unknown -passes=slp-vectorizer -S | FileCheck %s
3 ; RUN: opt < %s -mtriple=x86_64-unknown -mcpu=corei7-avx -passes=slp-vectorizer -S | FileCheck %s
4 ; RUN: opt < %s -mtriple=x86_64-unknown -mcpu=core-avx2 -passes=slp-vectorizer -S | FileCheck %s
6 %struct.ray = type { %struct.vec3, %struct.vec3 }
7 %struct.vec3 = type { double, double, double }
8 %struct.sphere = type { %struct.vec3, double, %struct.material, ptr }
9 %struct.material = type { %struct.vec3, double, double }
11 define i32 @ray_sphere(ptr nocapture noundef readonly %sph, ptr nocapture noundef readonly byval(%struct.ray) align 8 %ray, ptr nocapture noundef readnone %sp) {
12 ; CHECK-LABEL: @ray_sphere(
14 ; CHECK-NEXT: [[DIR:%.*]] = getelementptr inbounds [[STRUCT_RAY:%.*]], ptr [[RAY:%.*]], i64 0, i32 1
15 ; CHECK-NEXT: [[TMP0:%.*]] = load double, ptr [[DIR]], align 8
16 ; CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds [[STRUCT_RAY]], ptr [[RAY]], i64 0, i32 1, i32 1
17 ; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[Y]], align 8
18 ; CHECK-NEXT: [[MUL6:%.*]] = fmul double [[TMP1]], [[TMP1]]
19 ; CHECK-NEXT: [[TMP2:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP0]], double [[TMP0]], double [[MUL6]])
20 ; CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds [[STRUCT_RAY]], ptr [[RAY]], i64 0, i32 1, i32 2
21 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[Z]], align 8
22 ; CHECK-NEXT: [[TMP4:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP3]], double [[TMP3]], double [[TMP2]])
23 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[TMP0]], 2.000000e+00
24 ; CHECK-NEXT: [[TMP5:%.*]] = load double, ptr [[RAY]], align 8
25 ; CHECK-NEXT: [[TMP6:%.*]] = load double, ptr [[SPH:%.*]], align 8
26 ; CHECK-NEXT: [[SUB:%.*]] = fsub double [[TMP5]], [[TMP6]]
27 ; CHECK-NEXT: [[MUL17:%.*]] = fmul double [[TMP1]], 2.000000e+00
28 ; CHECK-NEXT: [[Y19:%.*]] = getelementptr inbounds [[STRUCT_VEC3:%.*]], ptr [[RAY]], i64 0, i32 1
29 ; CHECK-NEXT: [[TMP7:%.*]] = load double, ptr [[Y19]], align 8
30 ; CHECK-NEXT: [[Y21:%.*]] = getelementptr inbounds [[STRUCT_VEC3]], ptr [[SPH]], i64 0, i32 1
31 ; CHECK-NEXT: [[TMP8:%.*]] = load double, ptr [[Y21]], align 8
32 ; CHECK-NEXT: [[SUB22:%.*]] = fsub double [[TMP7]], [[TMP8]]
33 ; CHECK-NEXT: [[MUL23:%.*]] = fmul double [[MUL17]], [[SUB22]]
34 ; CHECK-NEXT: [[TMP9:%.*]] = tail call double @llvm.fmuladd.f64(double [[MUL]], double [[SUB]], double [[MUL23]])
35 ; CHECK-NEXT: [[MUL26:%.*]] = fmul double [[TMP3]], 2.000000e+00
36 ; CHECK-NEXT: [[Z28:%.*]] = getelementptr inbounds [[STRUCT_VEC3]], ptr [[RAY]], i64 0, i32 2
37 ; CHECK-NEXT: [[TMP10:%.*]] = load double, ptr [[Z28]], align 8
38 ; CHECK-NEXT: [[Z30:%.*]] = getelementptr inbounds [[STRUCT_VEC3]], ptr [[SPH]], i64 0, i32 2
39 ; CHECK-NEXT: [[TMP11:%.*]] = load double, ptr [[Z30]], align 8
40 ; CHECK-NEXT: [[SUB31:%.*]] = fsub double [[TMP10]], [[TMP11]]
41 ; CHECK-NEXT: [[TMP12:%.*]] = tail call double @llvm.fmuladd.f64(double [[MUL26]], double [[SUB31]], double [[TMP9]])
42 ; CHECK-NEXT: [[MUL42:%.*]] = fmul double [[TMP8]], [[TMP8]]
43 ; CHECK-NEXT: [[TMP13:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP6]], double [[TMP6]], double [[MUL42]])
44 ; CHECK-NEXT: [[TMP14:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP11]], double [[TMP11]], double [[TMP13]])
45 ; CHECK-NEXT: [[TMP15:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP5]], double [[TMP5]], double [[TMP14]])
46 ; CHECK-NEXT: [[TMP16:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP7]], double [[TMP7]], double [[TMP15]])
47 ; CHECK-NEXT: [[TMP17:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP10]], double [[TMP10]], double [[TMP16]])
48 ; CHECK-NEXT: [[FNEG:%.*]] = fneg double [[TMP6]]
49 ; CHECK-NEXT: [[TMP18:%.*]] = fneg double [[TMP8]]
50 ; CHECK-NEXT: [[NEG:%.*]] = fmul double [[TMP7]], [[TMP18]]
51 ; CHECK-NEXT: [[TMP19:%.*]] = tail call double @llvm.fmuladd.f64(double [[FNEG]], double [[TMP5]], double [[NEG]])
52 ; CHECK-NEXT: [[NEG78:%.*]] = fneg double [[TMP11]]
53 ; CHECK-NEXT: [[TMP20:%.*]] = tail call double @llvm.fmuladd.f64(double [[NEG78]], double [[TMP10]], double [[TMP19]])
54 ; CHECK-NEXT: [[TMP21:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP20]], double 2.000000e+00, double [[TMP17]])
55 ; CHECK-NEXT: [[RAD:%.*]] = getelementptr inbounds [[STRUCT_SPHERE:%.*]], ptr [[SPH]], i64 0, i32 1
56 ; CHECK-NEXT: [[TMP22:%.*]] = load double, ptr [[RAD]], align 8
57 ; CHECK-NEXT: [[NEG82:%.*]] = fneg double [[TMP22]]
58 ; CHECK-NEXT: [[TMP23:%.*]] = tail call double @llvm.fmuladd.f64(double [[NEG82]], double [[TMP22]], double [[TMP21]])
59 ; CHECK-NEXT: [[TMP24:%.*]] = fmul double [[TMP4]], -4.000000e+00
60 ; CHECK-NEXT: [[NEG86:%.*]] = fmul double [[TMP24]], [[TMP23]]
61 ; CHECK-NEXT: [[TMP25:%.*]] = tail call double @llvm.fmuladd.f64(double [[TMP12]], double [[TMP12]], double [[NEG86]])
62 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[TMP25]], 0.000000e+00
63 ; CHECK-NEXT: br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
65 ; CHECK-NEXT: [[CALL:%.*]] = tail call double @sqrt(double noundef [[TMP25]])
66 ; CHECK-NEXT: [[FNEG87:%.*]] = fneg double [[TMP12]]
67 ; CHECK-NEXT: [[MUL88:%.*]] = fmul double [[TMP4]], 2.000000e+00
68 ; CHECK-NEXT: [[TMP26:%.*]] = insertelement <2 x double> poison, double [[FNEG87]], i32 0
69 ; CHECK-NEXT: [[TMP27:%.*]] = insertelement <2 x double> [[TMP26]], double [[CALL]], i32 1
70 ; CHECK-NEXT: [[TMP28:%.*]] = shufflevector <2 x double> [[TMP27]], <2 x double> poison, <2 x i32> <i32 1, i32 poison>
71 ; CHECK-NEXT: [[TMP29:%.*]] = insertelement <2 x double> [[TMP28]], double [[TMP12]], i32 1
72 ; CHECK-NEXT: [[TMP30:%.*]] = fsub <2 x double> [[TMP27]], [[TMP29]]
73 ; CHECK-NEXT: [[TMP31:%.*]] = insertelement <2 x double> poison, double [[MUL88]], i32 0
74 ; CHECK-NEXT: [[TMP32:%.*]] = shufflevector <2 x double> [[TMP31]], <2 x double> poison, <2 x i32> zeroinitializer
75 ; CHECK-NEXT: [[TMP33:%.*]] = fdiv <2 x double> [[TMP30]], [[TMP32]]
76 ; CHECK-NEXT: [[TMP34:%.*]] = extractelement <2 x double> [[TMP33]], i32 1
77 ; CHECK-NEXT: [[CMP93:%.*]] = fcmp olt double [[TMP34]], 0x3EB0C6F7A0B5ED8D
78 ; CHECK-NEXT: [[TMP35:%.*]] = extractelement <2 x double> [[TMP33]], i32 0
79 ; CHECK-NEXT: [[CMP94:%.*]] = fcmp olt double [[TMP35]], 0x3EB0C6F7A0B5ED8D
80 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[CMP93]], i1 [[CMP94]], i1 false
81 ; CHECK-NEXT: br i1 [[OR_COND]], label [[CLEANUP]], label [[LOR_LHS_FALSE:%.*]]
82 ; CHECK: lor.lhs.false:
83 ; CHECK-NEXT: [[TMP36:%.*]] = fcmp ule <2 x double> [[TMP33]], splat (double 1.000000e+00)
84 ; CHECK-NEXT: [[TMP37:%.*]] = extractelement <2 x i1> [[TMP36]], i32 0
85 ; CHECK-NEXT: [[TMP38:%.*]] = extractelement <2 x i1> [[TMP36]], i32 1
86 ; CHECK-NEXT: [[OR_COND106:%.*]] = select i1 [[TMP38]], i1 true, i1 [[TMP37]]
87 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = zext i1 [[OR_COND106]] to i32
88 ; CHECK-NEXT: br label [[CLEANUP]]
90 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 0, [[IF_END]] ], [ [[SPEC_SELECT]], [[LOR_LHS_FALSE]] ]
91 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
94 %dir = getelementptr inbounds %struct.ray, ptr %ray, i64 0, i32 1
95 %0 = load double, ptr %dir, align 8
96 %y = getelementptr inbounds %struct.ray, ptr %ray, i64 0, i32 1, i32 1
97 %1 = load double, ptr %y, align 8
98 %mul6 = fmul double %1, %1
99 %2 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %mul6)
100 %z = getelementptr inbounds %struct.ray, ptr %ray, i64 0, i32 1, i32 2
101 %3 = load double, ptr %z, align 8
102 %4 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %2)
103 %mul = fmul double %0, 2.000000e+00
104 %5 = load double, ptr %ray, align 8
105 %6 = load double, ptr %sph, align 8
106 %sub = fsub double %5, %6
107 %mul17 = fmul double %1, 2.000000e+00
108 %y19 = getelementptr inbounds %struct.vec3, ptr %ray, i64 0, i32 1
109 %7 = load double, ptr %y19, align 8
110 %y21 = getelementptr inbounds %struct.vec3, ptr %sph, i64 0, i32 1
111 %8 = load double, ptr %y21, align 8
112 %sub22 = fsub double %7, %8
113 %mul23 = fmul double %mul17, %sub22
114 %9 = tail call double @llvm.fmuladd.f64(double %mul, double %sub, double %mul23)
115 %mul26 = fmul double %3, 2.000000e+00
116 %z28 = getelementptr inbounds %struct.vec3, ptr %ray, i64 0, i32 2
117 %10 = load double, ptr %z28, align 8
118 %z30 = getelementptr inbounds %struct.vec3, ptr %sph, i64 0, i32 2
119 %11 = load double, ptr %z30, align 8
120 %sub31 = fsub double %10, %11
121 %12 = tail call double @llvm.fmuladd.f64(double %mul26, double %sub31, double %9)
122 %mul42 = fmul double %8, %8
123 %13 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %mul42)
124 %14 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %13)
125 %15 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %14)
126 %16 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %15)
127 %17 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %16)
128 %fneg = fneg double %6
130 %neg = fmul double %7, %18
131 %19 = tail call double @llvm.fmuladd.f64(double %fneg, double %5, double %neg)
132 %neg78 = fneg double %11
133 %20 = tail call double @llvm.fmuladd.f64(double %neg78, double %10, double %19)
134 %21 = tail call double @llvm.fmuladd.f64(double %20, double 2.000000e+00, double %17)
135 %rad = getelementptr inbounds %struct.sphere, ptr %sph, i64 0, i32 1
136 %22 = load double, ptr %rad, align 8
137 %neg82 = fneg double %22
138 %23 = tail call double @llvm.fmuladd.f64(double %neg82, double %22, double %21)
139 %24 = fmul double %4, -4.000000e+00
140 %neg86 = fmul double %24, %23
141 %25 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %neg86)
142 %cmp = fcmp olt double %25, 0.000000e+00
143 br i1 %cmp, label %cleanup, label %if.end
145 if.end: ; preds = %entry
146 %call = tail call double @sqrt(double noundef %25) #3
147 %fneg87 = fneg double %12
148 %add = fsub double %call, %12
149 %mul88 = fmul double %4, 2.000000e+00
150 %div = fdiv double %add, %mul88
151 %sub90 = fsub double %fneg87, %call
152 %div92 = fdiv double %sub90, %mul88
153 %cmp93 = fcmp olt double %div, 0x3EB0C6F7A0B5ED8D
154 %cmp94 = fcmp olt double %div92, 0x3EB0C6F7A0B5ED8D
155 %or.cond = select i1 %cmp93, i1 %cmp94, i1 false
156 br i1 %or.cond, label %cleanup, label %lor.lhs.false
158 lor.lhs.false: ; preds = %if.end
159 %cmp95 = fcmp ule double %div, 1.000000e+00
160 %cmp97 = fcmp ule double %div92, 1.000000e+00
161 %or.cond106 = select i1 %cmp95, i1 true, i1 %cmp97
162 %spec.select = zext i1 %or.cond106 to i32
165 cleanup: ; preds = %lor.lhs.false, %if.end, %entry
166 %retval.0 = phi i32 [ 0, %entry ], [ 0, %if.end ], [ %spec.select, %lor.lhs.false ]
169 declare double @sqrt(double)
170 declare double @llvm.fmuladd.f64(double, double, double)