markus@x4 ffmpeg % cat diracdsp.i int *a; int b, c, d; void fn1(char *p1, int p2) { int x; while (1) { x = 0; for (; x < 8; x++) p1[0] = -a[0] * d + p1[0] * c + 1 >> b >> 1; p1 += p2; } } markus@x4 ffmpeg % gcc -c -O3 -march=amdfam10 diracdsp.i diracdsp.i: In function ‘fn1’: diracdsp.i:3:6: internal compiler error: in replace_one_candidate, at gimple-ssa-strength-reduction.c:3370 void fn1(char *p1, int p2) { ^~~ 0x1269fe9 replace_one_candidate ../../gcc/gcc/gimple-ssa-strength-reduction.c:3370 0x126db67 replace_profitable_candidates ../../gcc/gcc/gimple-ssa-strength-reduction.c:3481 0x126dadb replace_profitable_candidates ../../gcc/gcc/gimple-ssa-strength-reduction.c:3490 0x1271fc6 analyze_candidates_and_replace ../../gcc/gcc/gimple-ssa-strength-reduction.c:3569 0x1271fc6 execute ../../gcc/gcc/gimple-ssa-strength-reduction.c:3643
Started with r240945: commit 41b5b58f52ee35f1efe7eeac644db6992dac5499 Author: wschmidt <wschmidt@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon Oct 10 18:39:41 2016 +0000 2016-10-10 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77824 * gimple-ssa-strength-reduction.c (stmt_cost): Explicitly return zero cost for copies. (find_candidates_dom_walker::before_dom_children): Replace MODIFY_EXPR with SSA_NAME. (replace_mult_candidate): Likewise. (replace_profitable_candidates): Likewise.
Mine to investigate -- looks like enabling copies to be handled properly has exposed another "opportunity" here. Looks like probably another issue with pointer addition.
Does not reproduce on powerpc64le-unknown-linux-gnu. Can you please report the target triple?
Well, -march=amdfam10 is of course x86_64-pc-linux-gnu.
OK, thanks. While I get a cross built, could you please try the following patch? Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 240946) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -3367,7 +3367,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, { tree stride_type = TREE_TYPE (c->stride); tree orig_type = TREE_TYPE (orig_rhs2); - gcc_assert (repl_code != POINTER_PLUS_EXPR); + tree basis_type = TREE_TYPE (basis_name); if (types_compatible_p (orig_type, stride_type)) rhs2 = c->stride; @@ -3374,7 +3374,16 @@ replace_one_candidate (slsr_cand_t c, unsigned i, else rhs2 = introduce_cast_before_cand (c, orig_type, c->stride); - if (orig_code != MINUS_EXPR + if (POINTER_TYPE_P (basis_type)) + { + tree neg_stride = fold_unary (NEGATE_EXPR, sizetype, rhs2); + gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + gimple_assign_set_rhs_with_ops (&gsi, POINTER_PLUS_EXPR, + basis_name, neg_stride); + update_stmt (gsi_stmt (gsi)); + c->cand_stmt = gsi_stmt (gsi); + } + else if (orig_code != MINUS_EXPR || !operand_equal_p (basis_name, orig_rhs1, 0) || !operand_equal_p (rhs2, orig_rhs2, 0)) {
Unfortunately it doesn't work: dirac.i:3:6: internal compiler error: Segmentation fault void fn1(char *p1, int p2) { ^~~ 0xb6d367 crash_signal ../../gcc/gcc/toplev.c:337 0x7ff87981f10f ??? /home/markus/glibc/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0xb9bad2 contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*) ../../gcc/gcc/tree.h:3144 0xb9bad2 verify_gimple_assign_binary ../../gcc/gcc/tree-cfg.c:3732 0xbb479b verify_gimple_in_cfg(function*, bool) ../../gcc/gcc/tree-cfg.c:5135 0xa97737 execute_function_todo ../../gcc/gcc/passes.c:1964 0xa987ec execute_todo ../../gcc/gcc/passes.c:2014
OK, I can reproduce now, and understand the problem better. This patch fixes the problem. I'll regstrap it and get it committed shortly. Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 240946) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -2816,8 +2816,7 @@ analyze_increments (slsr_cand_t first_dep, machine else if (incr == 0 || incr == 1 || (incr == -1 - && (gimple_assign_rhs_code (first_dep->cand_stmt) - != POINTER_PLUS_EXPR))) + && !POINTER_TYPE_P (first_dep->cand_type))) incr_vec[i].cost = COST_NEUTRAL; /* FORNOW: If we need to add an initializer, give up if a cast from
Author: wschmidt Date: Thu Oct 13 01:08:20 2016 New Revision: 241082 URL: https://gcc.gnu.org/viewcvs?rev=241082&root=gcc&view=rev Log: 2016-10-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Use POINTER_TYPE_P on the candidate type to determine whether candidates in this chain require pointer arithmetic. Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-ssa-strength-reduction.c
Keeping this open until the fix has some burn-in time, planning to backport to GCC 6 and 5.
It still happens, but on another unit this time: markus@x4 ffmpeg % cat h264dsp.i extern int fn2(int); extern int fn3(int); int a, b, c; void fn1(long p1) { char *d; for (;; d += p1) { d[0] = fn2(1 >> a); fn3(0); fn3(c >> a); d[1] = fn3(d[1] * b + c >> a); d[4] = fn3(d[4] * b + c >> a); d[5] = fn3(d[5] * b + c >> a); } } markus@x4 ffmpeg % gcc -march=amdfam10 -O3 -c -S h264dsp.i h264dsp.i: In function ‘fn1’: h264dsp.i:4:6: internal compiler error: in replace_one_candidate, at gimple-ssa-strength-reduction.c:3369 void fn1(long p1) { ^~~ Simply building ffmpeg with -march=amdfam10 finds these bugs. Please consider reverting your original patch until you come up with solution.
Author: wschmidt Date: Thu Oct 13 15:34:22 2016 New Revision: 241125 URL: https://gcc.gnu.org/viewcvs?rev=241125&root=gcc&view=rev Log: 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Set cost to infinite when we have a pointer with an increment of -1. Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-ssa-strength-reduction.c
Just saw your request to include the test case. I will do this but may ask you to review the dejagnu bits for accuracy for your target, as these don't fire on arches I regularly build for.
Author: wschmidt Date: Thu Oct 13 19:50:41 2016 New Revision: 241139 URL: https://gcc.gnu.org/viewcvs?rev=241139&root=gcc&view=rev Log: 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gcc.dg/torture/pr77937-1.c: New. * gcc.dg/torture/pr77937-2.c: New. Added: trunk/gcc/testsuite/gcc.dg/torture/pr77937-1.c trunk/gcc/testsuite/gcc.dg/torture/pr77937-2.c Modified: trunk/gcc/testsuite/ChangeLog
Author: wschmidt Date: Mon Oct 17 14:22:22 2016 New Revision: 241243 URL: https://gcc.gnu.org/viewcvs?rev=241243&root=gcc&view=rev Log: [gcc] 2016-10-17 Bill Schmidt <wschmidt@linux.vnet.ibm.com> Backport from mainline 2016-10-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Use POINTER_TYPE_P on the candidate type to determine whether candidates in this chain require pointer arithmetic. 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Set cost to infinite when we have a pointer with an increment of -1. [gcc/testsuite] 2016-10-17 Bill Schmidt <wschmidt@linux.vnet.ibm.com> Backport from mainline 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gcc.dg/torture/pr77937-1.c: New. * gcc.dg/torture/pr77937-2.c: New. Added: branches/gcc-6-branch/gcc/testsuite/gcc.dg/torture/pr77937-1.c branches/gcc-6-branch/gcc/testsuite/gcc.dg/torture/pr77937-2.c Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/gimple-ssa-strength-reduction.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Author: wschmidt Date: Mon Oct 17 14:24:21 2016 New Revision: 241244 URL: https://gcc.gnu.org/viewcvs?rev=241244&root=gcc&view=rev Log: [gcc] 2016-10-17 Bill Schmidt <wschmidt@linux.vnet.ibm.com> Backport from mainline 2016-10-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Use POINTER_TYPE_P on the candidate type to determine whether candidates in this chain require pointer arithmetic. 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Set cost to infinite when we have a pointer with an increment of -1. [gcc/testsuite] 2016-10-17 Bill Schmidt <wschmidt@linux.vnet.ibm.com> Backport from mainline 2016-10-13 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77937 * gcc.dg/torture/pr77937-1.c: New. * gcc.dg/torture/pr77937-2.c: New. Added: branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr77937-1.c branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr77937-2.c Modified: branches/gcc-5-branch/gcc/ChangeLog branches/gcc-5-branch/gcc/gimple-ssa-strength-reduction.c branches/gcc-5-branch/gcc/testsuite/ChangeLog
Fixed. Further work for similar issues is being done under https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77916.
Author: wschmidt Date: Wed Oct 19 13:35:14 2016 New Revision: 241342 URL: https://gcc.gnu.org/viewcvs?rev=241342&root=gcc&view=rev Log: 2016-10-19 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/77916 PR tree-optimization/77937 * gimple-ssa-strength-reduction.c (analyze_increments): Remove stopgap fix. (insert_initializers): Requirement of initializer for -1 should be based on pointer-typedness of the candidate basis. Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-ssa-strength-reduction.c