| 1 |
/* PR tree-optimization/112822 */ |
| 2 |
/* { dg-do compile { target c++17 } } */ |
| 3 |
/* { dg-options "-w -O2" } */ |
| 4 |
|
| 5 |
/* Verify we do not ICE on the following noisy creduced test case. */ |
| 6 |
|
| 7 |
namespace b { |
| 8 |
typedef int c; |
| 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 { |
| 16 |
public: |
| 17 |
typedef __complex__ ah; |
| 18 |
template <typename e> af operator+=(e) { |
| 19 |
ah o; |
| 20 |
x = o; |
| 21 |
return *this; |
| 22 |
} |
| 23 |
ah x; |
| 24 |
}; |
| 25 |
} // namespace b |
| 26 |
namespace { |
| 27 |
enum { p }; |
| 28 |
enum { ac, ad }; |
| 29 |
struct ae; |
| 30 |
struct al; |
| 31 |
struct ag; |
| 32 |
typedef b::c an; |
| 33 |
namespace ai { |
| 34 |
template <typename aj> struct ak { typedef aj f; }; |
| 35 |
template <typename aj> using ar = typename ak<aj>::f; |
| 36 |
template <typename> struct am { |
| 37 |
enum { at }; |
| 38 |
}; |
| 39 |
template <typename, typename> struct ao { |
| 40 |
enum { at }; |
| 41 |
}; |
| 42 |
template <typename> struct ap; |
| 43 |
template <typename> struct aq { |
| 44 |
enum { at }; |
| 45 |
}; |
| 46 |
} // namespace ai |
| 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; |
| 53 |
namespace ai { |
| 54 |
template <typename, typename> struct bg; |
| 55 |
template <typename aj, int = bg<typename aj::bb, typename aj::bc>::bd> |
| 56 |
struct bk; |
| 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 { |
| 61 |
typedef bi f; |
| 62 |
}; |
| 63 |
template <typename aj, int bl> struct br { |
| 64 |
typedef typename bp<bl, typename bm<aj>::f>::f f; |
| 65 |
}; |
| 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; |
| 69 |
}; |
| 70 |
template <typename aj> struct bx { |
| 71 |
typedef typename bn<aj, typename ap<aj>::bs, aj ::bo>::f f; |
| 72 |
}; |
| 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 { |
| 75 |
enum { bw }; |
| 76 |
typedef b::n<bw, ca, typename bt<aj>::f> f; |
| 77 |
}; |
| 78 |
template <typename cd, typename = typename ap<cd>::bs> struct by { |
| 79 |
typedef be<cd> f; |
| 80 |
}; |
| 81 |
template <typename cd, typename bs> struct bz { |
| 82 |
typedef typename by<cd, bs>::f f; |
| 83 |
}; |
| 84 |
template <typename, typename, int> struct ch; |
| 85 |
template <typename ci, int cc> struct ch<ci, ci, cc> { typedef ci bd; }; |
| 86 |
} // namespace ai |
| 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; }; |
| 89 |
namespace ai { |
| 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 double co __attribute__ ((vector_size (16))); |
| 93 |
void ct(double *cr, co cs) { *(co *)cr = cs; } |
| 94 |
struct cq { |
| 95 |
co q; |
| 96 |
}; |
| 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>); |
| 103 |
} |
| 104 |
}; |
| 105 |
} // namespace ai |
| 106 |
template <typename cd> class ba<cd, ac> : public ay<cd> { |
| 107 |
public: |
| 108 |
typedef ai::ap<cd> bu; |
| 109 |
typedef b::n<ai::ap<cd>::bo, bu, b::n<ai::am<bu>::at, bu, bu>> cv; |
| 110 |
typedef ay<cd> db; |
| 111 |
db::dc; |
| 112 |
cv coeff(an dd, an col) const { return dc().coeff(dd, col); } |
| 113 |
}; |
| 114 |
template <typename cd> class cz : public ba<cd, ai::aq<cd>::at> { |
| 115 |
public: |
| 116 |
ai::ap<cd> b; |
| 117 |
enum { da, dg, dh, bv, bq, di = dg, bo }; |
| 118 |
}; |
| 119 |
template <typename cd> class be : public cz<cd> { |
| 120 |
public: |
| 121 |
typedef typename ai::ap<cd>::bu bu; |
| 122 |
typedef cz<cd> db; |
| 123 |
db::dc; |
| 124 |
template <typename de> cd &operator+=(const be<de> &); |
| 125 |
template <typename de> az<cd, de, ad> df(de); |
| 126 |
}; |
| 127 |
template <typename cd> struct ay { |
| 128 |
cd &dc() { return *static_cast<cd *>(this); } |
| 129 |
cd dc() const; |
| 130 |
}; |
| 131 |
template <typename, typename, int, typename> class dl; |
| 132 |
namespace ai { |
| 133 |
template <typename bb, typename bc, int dm> struct ap<az<bb, bc, dm>> { |
| 134 |
typedef bb dj; |
| 135 |
typedef bc r; |
| 136 |
typedef ap<dj> s; |
| 137 |
typedef ap<r> t; |
| 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; |
| 140 |
enum { bo }; |
| 141 |
}; |
| 142 |
} // namespace ai |
| 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>> { |
| 146 |
public: |
| 147 |
typedef dk bb; |
| 148 |
typedef Rhs_ bc; |
| 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; |
| 153 |
u lhs(); |
| 154 |
RhsNestedCleaned rhs(); |
| 155 |
}; |
| 156 |
template <typename bb, typename bc, int dm, typename> |
| 157 |
class dl : public ai::bz<az<bb, bc, dm>, al>::f {}; |
| 158 |
namespace ai { |
| 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; |
| 162 |
}; |
| 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 { |
| 166 |
public: |
| 167 |
plainobjectbase_evaluator_data(bu *ptr, an) : data(ptr) {} |
| 168 |
an outerStride() { return z; } |
| 169 |
bu *data; |
| 170 |
}; |
| 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; |
| 179 |
}; |
| 180 |
template <typename bu, int Rows, int Cols, int Options, int MaxRows, |
| 181 |
int MaxCols> |
| 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) {} |
| 186 |
}; |
| 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; |
| 192 |
}; |
| 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>( |
| 199 |
outer, inner); |
| 200 |
} |
| 201 |
}; |
| 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); |
| 207 |
} |
| 208 |
}; |
| 209 |
template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, |
| 210 |
typename Functor> |
| 211 |
class generic_dense_assignment_kernel { |
| 212 |
typedef typename DstEvaluatorTypeT::XprType DstXprType; |
| 213 |
|
| 214 |
public: |
| 215 |
typedef DstEvaluatorTypeT DstEvaluatorType; |
| 216 |
typedef SrcEvaluatorTypeT SrcEvaluatorType; |
| 217 |
typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, |
| 218 |
Functor> |
| 219 |
AssignmentTraits; |
| 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)); |
| 227 |
} |
| 228 |
template <int StoreMode, int LoadMode, typename cj> |
| 229 |
void assignPacketByOuterInner(an, an) { |
| 230 |
an dd; |
| 231 |
an col; |
| 232 |
cu<StoreMode, LoadMode, cj>(dd, col); |
| 233 |
} |
| 234 |
DstEvaluatorType m_dst; |
| 235 |
SrcEvaluatorType &m_src; |
| 236 |
Functor m_functor; |
| 237 |
DstXprType m_dstExpr; |
| 238 |
}; |
| 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, |
| 246 |
Functor> |
| 247 |
Kernel; |
| 248 |
Kernel kernel(dstEvaluator, srcEvaluator, func, dst); |
| 249 |
dense_assignment_loop<Kernel>::run(kernel); |
| 250 |
} |
| 251 |
template <typename, typename> struct AssignmentKind; |
| 252 |
struct Dense2Dense; |
| 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, |
| 257 |
typename = void> |
| 258 |
struct Assignment; |
| 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); |
| 267 |
} |
| 268 |
template <typename DstXprType, typename SrcXprType, typename Functor, |
| 269 |
typename Weak> |
| 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); |
| 273 |
} |
| 274 |
}; |
| 275 |
template <typename aj, int bl> struct plain_array { aj array[bl]; }; |
| 276 |
} // namespace ai |
| 277 |
template <typename aj, int bl, int, int av, int> class DenseStorage { |
| 278 |
ai::plain_array<aj, bl> m_data; |
| 279 |
|
| 280 |
public: |
| 281 |
an cols() { return av; } |
| 282 |
aj *data() { return m_data.array; } |
| 283 |
}; |
| 284 |
template <typename cd> class as : public ai::by<cd>::f { |
| 285 |
public: |
| 286 |
enum { Options }; |
| 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(); } |
| 293 |
}; |
| 294 |
namespace ai { |
| 295 |
template <typename Scalar_, int au, int av, int Options_, int MaxRows_, |
| 296 |
int MaxCols_> |
| 297 |
struct ap<aw<Scalar_, au, av, Options_, MaxRows_, MaxCols_>> { |
| 298 |
typedef Scalar_ bu; |
| 299 |
typedef ae cf; |
| 300 |
typedef al bs; |
| 301 |
enum { bo }; |
| 302 |
}; |
| 303 |
} // namespace ai |
| 304 |
template <typename Scalar_, int au, int, int Options_, int, int> |
| 305 |
class aw : public as<aw<Scalar_, au, Options_>> { |
| 306 |
public: |
| 307 |
template <typename T0, typename T1> aw(T0, T1) {} |
| 308 |
}; |
| 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>()); |
| 313 |
return dc(); |
| 314 |
} |
| 315 |
namespace ai { |
| 316 |
template <typename, typename> struct bg { |
| 317 |
enum { bd }; |
| 318 |
}; |
| 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) {} |
| 324 |
}; |
| 325 |
template <typename bb, typename bc, int cc> struct bk<az<bb, bc, ad>, cc> { |
| 326 |
typedef az<bb, bc, ad> XprType; |
| 327 |
bk(XprType xpr) |
| 328 |
: m_lhs(xpr.lhs()), m_rhs(xpr.rhs()), m_lhsImpl(m_lhs), m_rhsImpl(m_rhs) { |
| 329 |
} |
| 330 |
typedef typename cb<bb, bc::dg>::f LhsNested; |
| 331 |
typedef typename cb<bc, bb::da>::f dn; |
| 332 |
typedef LhsNested u; |
| 333 |
typedef dn RhsNestedCleaned; |
| 334 |
typedef u LhsEtorType; |
| 335 |
typedef RhsNestedCleaned RhsEtorType; |
| 336 |
template <int, typename bi> bi packet(an, an); |
| 337 |
LhsNested m_lhs; |
| 338 |
dn m_rhs; |
| 339 |
LhsEtorType m_lhsImpl; |
| 340 |
RhsEtorType m_rhsImpl; |
| 341 |
}; |
| 342 |
} // namespace ai |
| 343 |
} // namespace |
| 344 |
namespace Eigen { |
| 345 |
template <typename Type1, typename Type2> bool verifyIsApprox(Type1, Type2); |
| 346 |
} |
| 347 |
using namespace Eigen; |
| 348 |
template <typename TC, typename TA, typename TB> TC ref_prod(TC C, TA, TB B) { |
| 349 |
for (an i; i;) |
| 350 |
for (an j = 0; j < C.cols(); ++j) |
| 351 |
for (an k; k;) |
| 352 |
C.coeffRef(i, j) += B.coeff(k, j); |
| 353 |
return C; |
| 354 |
} |
| 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); |
| 360 |
aw D(C); |
| 361 |
verifyIsApprox(C += ci.df(B), ref_prod(D, ci, B)); |
| 362 |
} |
| 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); |
| 366 |
} |
| 367 |
template <typename aj> void test_lazy_l2() { |
| 368 |
test_lazy_all_layout<aj, 1, 4, 2>(); |
| 369 |
} |
| 370 |
void fn1() { test_lazy_l2<b::af<double>>(); } |