Debian Codegraph @

gcc/testsuite/g++.dg/vect/slp-pr87105.cc

raw
1 // { dg-do compile }
2 // { dg-require-effective-target c++11 }
3 // { dg-require-effective-target vect_double }
4 // For MIN/MAX recognition
5 // { dg-additional-options "-ffast-math" }
6 // { dg-skip-if "requires hosted libstdc++ for cmath" { ! hostedlib } }
7
8 #include <algorithm>
9 #include <cmath>
10 #include <stdint.h>
11
12 // Point structure [x, y]
13 struct Point {
14 double x, y;
15
16 inline Point() noexcept = default;
17 constexpr Point(const Point&) noexcept = default;
18
19 constexpr Point(double x, double y) noexcept
20 : x(x), y(y) {}
21 };
22
23 // Box structure [x0, y0, x1, y1]
24 struct Box {
25 double x0, y0, x1, y1;
26
27 inline void reset(double x0, double y0, double x1, double y1) noexcept {
28 this->x0 = x0;
29 this->y0 = y0;
30 this->x1 = x1;
31 this->y1 = y1;
32 }
33 };
34
35 // Overloads to make vector processing simpler.
36 static constexpr Point operator-(const Point& a) noexcept { return Point(-a.x, -a.y); }
37
38 static constexpr Point operator+(const Point& a, double b) noexcept
39 { return Point(a.x + b, a.y + b); }
40 static constexpr Point operator-(const Point& a, double b) noexcept
41 { return Point(a.x - b, a.y - b); }
42 static constexpr Point operator*(const Point& a, double b) noexcept
43 { return Point(a.x * b, a.y * b); }
44 static constexpr Point operator/(const Point& a, double b) noexcept
45 { return Point(a.x / b, a.y / b); }
46
47 static constexpr Point operator+(const Point& a, const Point& b) noexcept
48 { return Point(a.x + b.x, a.y + b.y); }
49 static constexpr Point operator-(const Point& a, const Point& b) noexcept
50 { return Point(a.x - b.x, a.y - b.y); }
51 static constexpr Point operator*(const Point& a, const Point& b) noexcept
52 { return Point(a.x * b.x, a.y * b.y); }
53 static constexpr Point operator/(const Point& a, const Point& b) noexcept
54 { return Point(a.x / b.x, a.y / b.y); }
55
56 static constexpr Point operator+(double a, const Point& b) noexcept
57 { return Point(a + b.x, a + b.y); }
58 static constexpr Point operator-(double a, const Point& b) noexcept
59 { return Point(a - b.x, a - b.y); }
60 static constexpr Point operator*(double a, const Point& b) noexcept
61 { return Point(a * b.x, a * b.y); }
62 static constexpr Point operator/(double a, const Point& b) noexcept
63 { return Point(a / b.x, a / b.y); }
64
65 // Min/Max - different semantics compared to std.
66 template<typename T> constexpr T myMin(const T& a, const T& b) noexcept
67 { return b < a ? b : a; }
68 template<typename T> constexpr T myMax(const T& a, const T& b) noexcept
69 { return a < b ? b : a; }
70
71 // Linear interpolation, works with points as well.
72 template<typename V, typename T = double>
73 inline V lerp(const V& a, const V& b, const T& t) noexcept {
74 return (a * (1.0 - t)) + (b * t);
75 }
76
77 // Merge a point into a box by possibly increasing its bounds.
78 inline void boxMergePoint(Box& box, const Point& p) noexcept {
79 box.x0 = myMin(box.x0, p.x);
80 box.y0 = myMin(box.y0, p.y);
81 box.x1 = myMax(box.x1, p.x);
82 box.y1 = myMax(box.y1, p.y);
83 }
84
85 void quadBoundingBoxA(const Point bez[3], Box& bBox) noexcept {
86 // Bounding box of start and end points.
87 bBox.reset(myMin(bez[0].x, bez[2].x), myMin(bez[0].y, bez[2].y),
88 myMax(bez[0].x, bez[2].x), myMax(bez[0].y, bez[2].y));
89
90 Point t = (bez[0] - bez[1]) / (bez[0] - bez[1] * 2.0 + bez[2]);
91
92 t.x = myMax(t.x, 0.0);
93 t.y = myMax(t.y, 0.0);
94 t.x = myMin(t.x, 1.0);
95 t.y = myMin(t.y, 1.0);
96
97 boxMergePoint(bBox, lerp(lerp(bez[0], bez[1], t),
98 lerp(bez[1], bez[2], t), t));
99 }
100
101 // We should have if-converted everything down to straight-line code
102 // { dg-final { scan-tree-dump-times "<bb \[0-9\]+>" 1 "slp2" } }
103 // { dg-final { scan-tree-dump-times "Basic block will be vectorized using SLP" 1 "slp2" { xfail { { ! vect_element_align } && { ! vect_hw_misalign } } } } }
104 // It's a bit awkward to detect that all stores were vectorized but the
105 // following more or less does the trick
106 // { dg-final { scan-tree-dump "vect_\[^\r\m\]* = MIN" "slp2" { xfail { { ! vect_element_align } && { ! vect_hw_misalign } } } } }