Debian Codegraph @

gcc/testsuite/g++.dg/opt/strength-reduce.C

raw
1 // This testcase was miscompiled on s390x, because strength-reduction
2 // did not see biv in C::foo as used after loop, but it was used
3 // in a REG_EQUAL note.
4 // { dg-do run }
5 // { dg-options "-O2" }
6
7 extern "C" void abort (void);
8
9 struct C
10 {
11 int foo (char ch, int offset = __INT_MAX__) const;
12 int bar (int offset, char c) const;
13 const char *a;
14 };
15
16 int C::bar (int offset, char c) const
17 {
18 char ch = a[offset];
19 if (ch < c)
20 return -1;
21 if (ch > c)
22 return 1;
23 return 0;
24 }
25
26 int C::foo (char ch, int offset) const
27 {
28 int len = __builtin_strlen (a);
29 if (len == 0)
30 return __INT_MAX__;
31 if (offset >= len)
32 offset = len - 1;
33
34 while (bar (offset, ch) != 0)
35 {
36 if (offset == 0)
37 return __INT_MAX__;
38 offset--;
39 }
40
41 return offset;
42 }
43
44 int main (void)
45 {
46 C c;
47 c.a = "/some/dir/file.ext";
48 if (c.foo ('/') != 9)
49 abort ();
50 return 0;
51 }