void bar (); int foo (void) { if ("<12ers" + 1 == 0) bar (); } which is reduced from from extern const char tree_code_type[]; extern char *strchr (__const char *__s, int __c) __attribute__ ((__pure__)); extern void abort (void) __attribute__ ((__noreturn__)); int foo (int a) { if (tree_code_type[a] == '1') if (strchr ("<12ers", tree_code_type[a]) == 0) abort (); } which is in turn reduced from find_base_decl() in alias.c.
I think the two test cases are not related at all, the second one only needs to fold strchr ("<12ers", '1' ) to 1 (which it does when expanding to RTL). There are two problems with the first testcase, first "<12ers" + 1 == 0 is "folded" to "<12ers" == -1 by fold, and but if you add a tempary variable then "< 12ers" + 1 == 0 is not folded to false. Confirmed otherwise, the orginal testcase is not done on the RTL level but the other two are.
Andrew, I forgot to say that the first testcase can be obtained more or less if you use Steven's strchr optimization patch. IIRC, His strchr optimization happens in CCP, so fold does not get to fold "<12ers" + 1 == 0 into false. In any case, all the stupidity in this area should go away.
See also PR 14819. If strchr() is folded to NULL, we don't have to worry about anything. Otherwise, resolution of this PR is important.
Now that Steven's strchr patch is in, let me reiterate the problem. void bar (void); void foo (void) { int c = '1'; if (strchr ("<12ers", c) == 0) bar (); } void baz (void) { int c = '1'; if ("<12ers" + 1 == 0) bar (); } The last tree-ssa form looks like: ;; Function foo (foo) foo () { int c; char * T.0; <bb 0>: T.0_2 = "<12ers" + 1B; if (T.0_2 == 0B) goto <L0>; else goto <L1>; <L0>:; bar () [tail call]; <L1>:; return; } ;; Function baz (baz) baz () { int c; <bb 0>: if ("<12ers" == -1B) goto <L0>; else goto <L1>; <L0>:; bar () [tail call]; <L1>:; return; } In either case, we miss the folding opportunity.
"int c = '1';" in baz() in comment #4 is an unintended garbage. Please ignore it.
I should note that "12ers" == 0 is folded to false by: /* If this is an equality comparison of the address of a non-weak object against zero, then we know the result. */ So improving that part will help.
I should note that the first testcase in comment #0 in the bug is fixed but not the second, non reduced one.
Just to clarify what testcase is still broken, here it is: void baz (void) { if ("<12ers" + 1 == 0) bar (); } ------ The reason why strchr testcase is fixed is because we turn the strchr call into &"<12ers"[1].
This appears to be fixed in 4.6.0. Mark as resolved?
(In reply to comment #9) > This appears to be fixed in 4.6.0. Mark as resolved? Need to add a few testcases first.
Author: rguenth Date: Thu Apr 28 09:55:41 2011 New Revision: 173064 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173064 Log: 2011-04-28 Richard Guenther <rguenther@suse.de> PR tree-optimization/40052 PR tree-optimization/15347 * gcc.dg/tree-ssa/vrp57.c: New testcase. * gcc.dg/pr15347.c: Likewise. Added: trunk/gcc/testsuite/gcc.dg/pr15347.c trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp57.c Modified: trunk/gcc/testsuite/ChangeLog
Fixed. Thanks for noticing.
Fi-xed.