2 // { dg-options "-O3 -fdump-tree-fre2" }
4 #define assume(x) if(!(x))__builtin_unreachable()
6 inline void* operator new(__SIZE_TYPE__ n){ return __builtin_malloc(n); }
7 inline void operator delete(void *p) { __builtin_free(p); }
8 // C++14 sized deallocation function
9 inline void operator delete(void *p, __SIZE_TYPE__) { __builtin_free(p); }
16 I(double d = 0) : o (new O) { o->num = d; o->count = 1; }
17 I(I const&i) { assume(i.o->count >= 1); o = i.o; ++o->count; }
18 I& operator=(I const&i) { I(i).swap(*this); return *this; }
19 ~I() { if (--o->count == 0) delete o; }
20 void swap(I& i) { O *tmp = o; o = i.o; i.o = tmp; }
21 I& operator*= (I const&i) {
22 if (o->count > 1) *this = I(o->num);
26 I& operator-= (I const&i) {
27 if (o->count > 1) *this = I(o->num);
32 inline I operator* (I a, I const&b) { return a *= b; }
33 inline I operator- (I a, I const&b) { return a -= b; }
34 inline bool operator< (I const&a, I const&b) { return a.o->num < b.o->num; }
36 bool f(I a, I b, I c, I d) {
37 I tmp = (a * d - b * c) * (a * b - c * d);
41 // We should be able to CSE most references to count and thus remove
42 // a bunch of conditional free()s and unreachable()s.
43 // This works only if everything is inlined into 'f'.
45 // { dg-final { scan-tree-dump-times ";; Function" 1 "fre2" } }
46 // { dg-final { scan-tree-dump-times "free" 18 "fre2" } }
47 // { dg-final { scan-tree-dump-times "unreachable" 11 "fre2" } }
48 // { dg-final { cleanup-tree-dump "fre2" } }