aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/tree-ssa/pr61034.C
blob: 6a76adb5b80f7b8b2f14e925925618e4913a9f6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// { dg-do compile }
// { dg-options "-O2 -fdump-tree-fre3 -fdump-tree-optimized -fdelete-null-pointer-checks --param early-inlining-insns-O2=14 --param max-inline-insns-single-O2=200" }

#define assume(x) if(!(x))__builtin_unreachable()

inline void* operator new(__SIZE_TYPE__ n){ return __builtin_malloc(n); }
inline void operator delete(void *p) { __builtin_free(p); }
// C++14 sized deallocation function
inline void operator delete(void *p, __SIZE_TYPE__) { __builtin_free(p); }
struct O {
    double num;
    int count;
};
struct I {
    O *o;
    I(double d = 0) : o (new O) { o->num = d; o->count = 1; }
    I(I const&i) { assume(i.o->count >= 1); o = i.o; ++o->count; }
    I& operator=(I const&i) { I(i).swap(*this); return *this; }
    ~I() { if (--o->count == 0) delete o; }
    void swap(I& i) { O *tmp = o; o = i.o; i.o = tmp; }
    I& operator*= (I const&i) {
	if (o->count > 1) *this = I(o->num);
	o->num *= i.o->num;
	return *this;
    }
    I& operator-= (I const&i) {
	if (o->count > 1) *this = I(o->num);
	o->num -= i.o->num;
	return *this;
    }
};
inline I operator* (I a, I const&b) { return a *= b; }
inline I operator- (I a, I const&b) { return a -= b; }
inline bool operator< (I const&a, I const&b) { return a.o->num < b.o->num; }

bool f(I a, I b, I c, I d) {
    I tmp = (a * d - b * c) * (a * b - c * d);
    return tmp < 42;
}

// We should be able to CSE most references to count and thus remove
// a bunch of conditional free()s and unreachable()s.
// This works only if everything is inlined into 'f'.

// { dg-final { scan-tree-dump-times ";; Function" 1 "fre3" } }
// { dg-final { scan-tree-dump-times "unreachable" 11 "fre3" } }

// Note that depending on PUSH_ARGS_REVERSED we are presented with
// a different initial CFG and thus the final outcome is different

// { dg-final { scan-tree-dump-times "free" 10 "fre3" { target x86_64-*-* i?86-*-* } } }
// { dg-final { scan-tree-dump-times "free" 14 "fre3" { target aarch64-*-* ia64-*-* arm-*-* hppa*-*-* sparc*-*-* powerpc*-*-* alpha*-*-* } } }
// { dg-final { scan-tree-dump-times "free" 0 "optimized" } }