| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target c++17 } */ |
| 3 |
/* { dg-options "-O2 -fdump-tree-fre3" } */ |
| 4 |
|
| 5 |
struct _Base |
| 6 |
{ |
| 7 |
int _M_data = 0; |
| 8 |
}; |
| 9 |
|
| 10 |
struct _Wrapper : _Base |
| 11 |
{ |
| 12 |
_Wrapper(int) {} |
| 13 |
|
| 14 |
bool _M_is_constprop() { return __builtin_constant_p(_M_data); } |
| 15 |
}; |
| 16 |
|
| 17 |
struct _Impl |
| 18 |
{ |
| 19 |
_Wrapper _S_multiplies(_Wrapper __x, _Wrapper __y) |
| 20 |
{ |
| 21 |
if (__x._M_is_constprop() || __y._M_is_constprop()) |
| 22 |
return __y; |
| 23 |
return 0; |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
struct _TupleData |
| 28 |
{ |
| 29 |
_Wrapper first; |
| 30 |
int second; |
| 31 |
}; |
| 32 |
|
| 33 |
struct _Tuple : _TupleData |
| 34 |
{ |
| 35 |
template <typename _Fp> |
| 36 |
_Tuple _M_apply_per_chunk(_Fp __fun, _Tuple __y) |
| 37 |
{ |
| 38 |
return {__fun(first, __y.first), second}; |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
struct _ImplFixed |
| 43 |
{ |
| 44 |
static _Tuple _S_multiplies(_Tuple __x, _Tuple __y) |
| 45 |
{ |
| 46 |
return __x._M_apply_per_chunk( |
| 47 |
[]( auto __xx, auto __yy) { |
| 48 |
return _Impl()._S_multiplies(__xx, __yy); |
| 49 |
}, |
| 50 |
__y); |
| 51 |
} |
| 52 |
}; |
| 53 |
|
| 54 |
class simd |
| 55 |
{ |
| 56 |
public: |
| 57 |
[[__gnu__::__always_inline__]] friend simd operator*(simd __x, simd __y) |
| 58 |
{ return _ImplFixed::_S_multiplies(__x._M_data, __y._M_data); } |
| 59 |
|
| 60 |
simd(_Tuple __init) : _M_data(__init) {} |
| 61 |
|
| 62 |
_Tuple _M_data; |
| 63 |
}; |
| 64 |
|
| 65 |
int main() |
| 66 |
{ |
| 67 |
simd({0, 0}) * simd({0, 0}); |
| 68 |
} |
| 69 |
|
| 70 |
/* FRE3 should elide all conditionals in the remaining main. */ |
| 71 |
/* { dg-final { scan-tree-dump-times "<bb" 1 "fre3" } } */ |