1 /* PR tree-optimization/112822 */
2 /* { dg-do compile { target c++17 } } */
3 /* { dg-options "-w -O2" } */
5 /* Verify we do not ICE on the following noisy creduced test case. */
9 template <bool, typename> struct d;
10 template <typename e> struct d<true, e> { using f = e; };
11 template <bool, typename, typename> struct aa;
12 template <typename g, typename h> struct aa<false, g, h> { using f = h; };
13 template <bool l, typename e> using ab = typename d<l, e>::f;
14 template <bool l, typename g, typename h> using n = typename aa<l, g, h>::f;
15 template <typename> class af {
17 typedef __complex__ ah;
18 template <typename e> af operator+=(e) {
34 template <typename aj> struct ak { typedef aj f; };
35 template <typename aj> using ar = typename ak<aj>::f;
36 template <typename> struct am {
39 template <typename, typename> struct ao {
42 template <typename> struct ap;
43 template <typename> struct aq {
47 template <typename> struct ay;
48 template <typename> class as;
49 template <typename, int> class ba;
50 template <typename, int au, int av, int = 0, int = au, int = av> class aw;
51 template <typename> class be;
52 template <typename, typename, int> class az;
54 template <typename, typename> struct bg;
55 template <typename aj, int = bg<typename aj::bb, typename aj::bc>::bd>
57 template <typename, typename> struct bf;
58 template <typename> struct bm;
59 template <typename> struct bh;
60 template <int, typename bi, bool = ao<bi, typename bh<bi>::bj>::at> struct bp {
63 template <typename aj, int bl> struct br {
64 typedef typename bp<bl, typename bm<aj>::f>::f f;
66 template <typename, typename, int> struct bn;
67 template <typename aj, int bo> struct bn<aj, al, bo> {
68 typedef aw<typename aj ::bu, aj ::bv, aj ::bq> f;
70 template <typename aj> struct bx {
71 typedef typename bn<aj, typename ap<aj>::bs, aj ::bo>::f f;
73 template <typename aj> struct bt { typedef b::n<0, aj, aj> f; };
74 template <typename aj, int, typename ca = typename bx<aj>::f> struct cb {
76 typedef b::n<bw, ca, typename bt<aj>::f> f;
78 template <typename cd, typename = typename ap<cd>::bs> struct by {
81 template <typename cd, typename bs> struct bz {
82 typedef typename by<cd, bs>::f f;
84 template <typename, typename, int> struct ch;
85 template <typename ci, int cc> struct ch<ci, ci, cc> { typedef ci bd; };
87 template <typename ck, typename ce, typename = ai::bf<ck, ce>> struct cg;
88 template <typename aj, typename cm> struct cg<aj, cm> { typedef aj cn; };
90 template <typename cj, int> cj cp;
91 template <typename bu, typename cj, int> void cl(bu *cr, cj cs) { ct(cr, cs); }
92 typedef __attribute__((altivec(vector__))) double co;
93 void ct(double *cr, co cs) { *(co *)cr = cs; }
97 template <> struct bm<b::af<double>> { typedef cq f; };
98 template <> struct bh<cq> { typedef cq bj; };
99 void ct(b::af<double> *cr, cq cs) { ct((double *)cr, cs.q); }
100 template <typename cw, typename> struct cx {
101 template <int cy, typename cj> void cu(cw *a, cj) {
102 cl<cw, cj, cy>(a, cp<cj, cy>);
106 template <typename cd> class ba<cd, ac> : public ay<cd> {
108 typedef ai::ap<cd> bu;
109 typedef b::n<ai::ap<cd>::bo, bu, b::n<ai::am<bu>::at, bu, bu>> cv;
112 cv coeff(an dd, an col) const { return dc().coeff(dd, col); }
114 template <typename cd> class cz : public ba<cd, ai::aq<cd>::at> {
117 enum { da, dg, dh, bv, bq, di = dg, bo };
119 template <typename cd> class be : public cz<cd> {
121 typedef typename ai::ap<cd>::bu bu;
124 template <typename de> cd &operator+=(const be<de> &);
125 template <typename de> az<cd, de, ad> df(de);
127 template <typename cd> struct ay {
128 cd &dc() { return *static_cast<cd *>(this); }
131 template <typename, typename, int, typename> class dl;
133 template <typename bb, typename bc, int dm> struct ap<az<bb, bc, dm>> {
138 typedef typename cg<typename dj ::bu, typename r ::bu>::cn bu;
139 typedef typename ch<typename s::cf, typename t::cf, bg<bb, bc>::bd>::bd cf;
143 template <typename dk, typename Rhs_, int dm>
144 class az : public dl<dk, Rhs_, dm,
145 ai::ch<ai::ap<dk>, ai::ap<Rhs_>, ai::bg<dk, Rhs_>::bd>> {
149 typedef typename ai::bt<bb>::f LhsNested;
150 typedef typename ai::bt<bc>::f dn;
151 typedef ai::ar<LhsNested> u;
152 typedef ai::ar<dn> RhsNestedCleaned;
154 RhsNestedCleaned rhs();
156 template <typename bb, typename bc, int dm, typename>
157 class dl : public ai::bz<az<bb, bc, dm>, al>::f {};
159 template <typename> struct v { typedef ag w; };
160 template <typename aj> struct evaluator_traits_base {
161 typedef typename v<typename ap<aj>::cf>::w w;
163 template <typename aj> struct ax : evaluator_traits_base<aj> {};
164 template <typename> struct y { static const bool at = false; };
165 template <typename bu, int z> class plainobjectbase_evaluator_data {
167 plainobjectbase_evaluator_data(bu *ptr, an) : data(ptr) {}
168 an outerStride() { return z; }
171 template <typename cd> struct evaluator {
172 typedef cd PlainObjectType;
173 typedef typename PlainObjectType::bu bu;
174 enum { IsVectorAtCompileTime };
175 enum { OuterStrideAtCompileTime };
176 evaluator(PlainObjectType &m) : m_d(m.data(), IsVectorAtCompileTime) {}
177 bu &coeffRef(an, an) { return m_d.data[m_d.outerStride()]; }
178 plainobjectbase_evaluator_data<bu, OuterStrideAtCompileTime> m_d;
180 template <typename bu, int Rows, int Cols, int Options, int MaxRows,
182 struct evaluator<aw<bu, Rows, Cols, Options, MaxRows, MaxCols>>
183 : evaluator<as<aw<bu, Rows, Cols>>> {
184 typedef aw<bu, Rows, Cols> XprType;
185 evaluator(XprType &m) : evaluator<as<XprType>>(m) {}
187 template <typename DstEvaluator, typename, typename>
188 struct copy_using_evaluator_traits {
189 typedef typename DstEvaluator::bu cw;
190 enum { RestrictedInnerSize };
191 typedef typename br<cw, RestrictedInnerSize>::f bi;
193 template <typename Kernel, an, int>
194 struct copy_using_evaluator_innervec_CompleteUnrolling {
195 typedef typename Kernel::bi bi;
196 enum { outer, inner, SrcAlignment, DstAlignment };
197 static void run(Kernel kernel) {
198 kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, bi>(
202 template <typename Kernel> struct dense_assignment_loop {
203 static void run(Kernel kernel) {
204 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
205 copy_using_evaluator_innervec_CompleteUnrolling<
206 Kernel, 0, DstXprType::dh>::run(kernel);
209 template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT,
211 class generic_dense_assignment_kernel {
212 typedef typename DstEvaluatorTypeT::XprType DstXprType;
215 typedef DstEvaluatorTypeT DstEvaluatorType;
216 typedef SrcEvaluatorTypeT SrcEvaluatorType;
217 typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT,
220 typedef typename AssignmentTraits::bi bi;
221 generic_dense_assignment_kernel(DstEvaluatorType dst, SrcEvaluatorType src,
222 Functor, DstXprType dstExpr)
223 : m_dst(dst), m_src(src), m_dstExpr(dstExpr) {}
224 template <int StoreMode, int LoadMode, typename cj> void cu(an dd, an col) {
225 m_functor.template cu<StoreMode>(
226 &m_dst.coeffRef(dd, col), m_src.template packet<LoadMode, cj>(dd, col));
228 template <int StoreMode, int LoadMode, typename cj>
229 void assignPacketByOuterInner(an, an) {
232 cu<StoreMode, LoadMode, cj>(dd, col);
234 DstEvaluatorType m_dst;
235 SrcEvaluatorType &m_src;
237 DstXprType m_dstExpr;
239 template <typename DstXprType, typename SrcXprType, typename Functor>
240 void call_dense_assignment_loop(DstXprType &dst, SrcXprType src, Functor func) {
241 typedef evaluator<DstXprType> DstEvaluatorType;
242 typedef evaluator<SrcXprType> SrcEvaluatorType;
243 SrcEvaluatorType srcEvaluator(src);
244 DstEvaluatorType dstEvaluator(dst);
245 typedef generic_dense_assignment_kernel<DstEvaluatorType, SrcEvaluatorType,
248 Kernel kernel(dstEvaluator, srcEvaluator, func, dst);
249 dense_assignment_loop<Kernel>::run(kernel);
251 template <typename, typename> struct AssignmentKind;
253 template <> struct AssignmentKind<ag, ag> { typedef Dense2Dense Kind; };
254 template <typename DstXprType, typename SrcXprType, typename,
255 typename = typename AssignmentKind<typename ax<DstXprType>::w,
256 typename ax<SrcXprType>::w>::Kind,
259 template <typename Dst, typename Src, typename Func>
260 void call_assignment(Dst &dst, Src src, Func func,
261 b::ab<!y<Src>::at, void *> = 0) {
262 enum { NeedToTranspose };
263 typedef b::n<NeedToTranspose, Dst, Dst> ActualDstTypeCleaned;
264 typedef b::n<NeedToTranspose, Dst, Dst &> ActualDstType;
265 ActualDstType actualDst(dst);
266 Assignment<ActualDstTypeCleaned, Src, Func>::run(actualDst, src, func);
268 template <typename DstXprType, typename SrcXprType, typename Functor,
270 struct Assignment<DstXprType, SrcXprType, Functor, Weak> {
271 static void run(DstXprType &dst, SrcXprType src, Functor func) {
272 call_dense_assignment_loop(dst, src, func);
275 template <typename aj, int bl> struct plain_array { aj array[bl]; };
277 template <typename aj, int bl, int, int av, int> class DenseStorage {
278 ai::plain_array<aj, bl> m_data;
281 an cols() { return av; }
282 aj *data() { return m_data.array; }
284 template <typename cd> class as : public ai::by<cd>::f {
287 typedef typename ai::by<cd>::f db;
288 typedef typename ai::ap<cd>::bu bu;
289 DenseStorage<bu, db::di, db::da, db::dg, Options> m_storage;
290 an cols() { return m_storage.cols(); }
291 bu &coeffRef(an, an colId) { return data()[colId]; }
292 bu *data() { return m_storage.data(); }
295 template <typename Scalar_, int au, int av, int Options_, int MaxRows_,
297 struct ap<aw<Scalar_, au, av, Options_, MaxRows_, MaxCols_>> {
304 template <typename Scalar_, int au, int, int Options_, int, int>
305 class aw : public as<aw<Scalar_, au, Options_>> {
307 template <typename T0, typename T1> aw(T0, T1) {}
309 template <typename cd>
310 template <typename de>
311 cd &be<cd>::operator+=(const be<de> &other) {
312 call_assignment(dc(), other.dc(), ai::cx<bu, bu>());
316 template <typename, typename> struct bg {
319 template <typename bb, typename bc, int Options>
320 struct evaluator<az<bb, bc, Options>> : bk<az<bb, bc, Options>> {
321 typedef az<bb, bc, Options> XprType;
322 typedef bk<XprType> db;
323 evaluator(XprType xpr) : db(xpr) {}
325 template <typename bb, typename bc, int cc> struct bk<az<bb, bc, ad>, cc> {
326 typedef az<bb, bc, ad> XprType;
328 : m_lhs(xpr.lhs()), m_rhs(xpr.rhs()), m_lhsImpl(m_lhs), m_rhsImpl(m_rhs) {
330 typedef typename cb<bb, bc::dg>::f LhsNested;
331 typedef typename cb<bc, bb::da>::f dn;
333 typedef dn RhsNestedCleaned;
334 typedef u LhsEtorType;
335 typedef RhsNestedCleaned RhsEtorType;
336 template <int, typename bi> bi packet(an, an);
339 LhsEtorType m_lhsImpl;
340 RhsEtorType m_rhsImpl;
345 template <typename Type1, typename Type2> bool verifyIsApprox(Type1, Type2);
347 using namespace Eigen;
348 template <typename TC, typename TA, typename TB> TC ref_prod(TC C, TA, TB B) {
350 for (an j = 0; j < C.cols(); ++j)
352 C.coeffRef(i, j) += B.coeff(k, j);
355 template <typename aj, int Rows, int Cols, int Depth, int OC, int OA, int OB>
356 b::ab<!0, void> test_lazy_single(int rows, int cols, int depth) {
357 aw<aj, Depth, OA> ci(rows, depth);
358 aw<aj, Cols, OB> B(depth, cols);
359 aw<aj, Rows, OC> C(rows, cols);
361 verifyIsApprox(C += ci.df(B), ref_prod(D, ci, B));
363 template <typename aj, int Rows, int Cols, int Depth>
364 void test_lazy_all_layout(int rows = Rows, int cols = Cols, int depth = Depth) {
365 test_lazy_single<aj, Rows, Cols, Depth, p, p, p>(rows, cols, depth);
367 template <typename aj> void test_lazy_l2() {
368 test_lazy_all_layout<aj, 1, 4, 2>();
370 void fn1() { test_lazy_l2<b::af<double>>(); }