Merge from mainline
[official-gcc.git] / gcc / testsuite / g++.dg / opt / strength-reduce.C
blob3fee937f1c15dafd96170218a60f3b16cc2ab9d4
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" }
7 extern "C" void abort (void);
9 struct C
11   int foo (char ch, int offset = __INT_MAX__) const;
12   int bar (int offset, char c) const;
13    const char *a;
16 int C::bar (int offset, char c) const
18   char ch = a[offset];
19   if (ch < c)
20     return -1;
21   if (ch > c)
22     return 1;
23   return 0;
26 int C::foo (char ch, int offset) const
28   int len = __builtin_strlen (a);
29   if (len == 0)
30     return __INT_MAX__;
31   if (offset >= len)
32     offset = len - 1;
34   while (bar (offset, ch) != 0)
35     {
36       if (offset == 0)
37         return __INT_MAX__;
38       offset--;
39     }
41   return offset;
44 int main (void)
46   C c;
47   c.a = "/some/dir/file.ext";
48   if (c.foo ('/') != 9)
49     abort ();
50   return 0;