1 /* PR tree-optimization/34244 */ 2 /* { dg-do run } */ 3 /* { dg-options "-O2 " } */ 4 GetParent(void)5int __attribute__((noinline)) GetParent(void) 6 { 7 static int count = 0; 8 count++; 9 switch (count) 10 { 11 case 1: 12 case 3: 13 case 4: 14 return 1; 15 default: 16 return 0; 17 } 18 } FindCommonAncestor(int aNode1,int aNode2)19int __attribute__((noinline)) FindCommonAncestor(int aNode1, int aNode2) 20 { 21 if (aNode1 && aNode2) { 22 int offset = 0; 23 int anc1 = aNode1; 24 for (;;) { 25 ++offset; 26 int parent = GetParent(); 27 if (!parent) 28 break; 29 anc1 = parent; 30 } 31 int anc2 = aNode2; 32 for (;;) { 33 --offset; 34 int parent = GetParent(); 35 if (!parent) 36 break; 37 anc2 = parent; 38 } 39 if (anc1 == anc2) { 40 anc1 = aNode1; 41 anc2 = aNode2; 42 while (offset > 0) { 43 anc1 = GetParent(); 44 --offset; 45 } 46 while (offset < 0) { 47 anc2 = GetParent(); 48 ++offset; 49 } 50 while (anc1 != anc2) { 51 anc1 = GetParent(); 52 anc2 = GetParent(); 53 } 54 return anc1; 55 } 56 } 57 return 0; 58 } 59 extern void abort (void); main()60int main() 61 { 62 if (FindCommonAncestor (1, 1) != 0) 63 abort (); 64 return 0; 65 } 66