Link to the Compiler Explorer: https://godbolt.org/z/jbKEn7Tdq Reproducer: char a, b; extern unsigned short c[]; extern bool d[]; const unsigned short &e(const unsigned short &f, const unsigned short &g) { if (g < f) return g; return f; } void k() { for (int h = 0; b; h += 3) for (unsigned long i = 0; i < 11104842004558084287ULL; i += -11104842004558084300ULL) for (bool j(e(6, e(6, c[h + i]))); j < (bool)a; j = 7) d[7] = 0; } Error: >$ g++ -O3 -c func.cpp during GIMPLE pass: unrolljam func.cpp: In function 'void k()': func.cpp:9:6: internal compiler error: in adjust_unroll_factor, at gimple-loop-jam.c:407 9 | void k() { | ^ 0x93ebce adjust_unroll_factor /testing/gcc/gcc_src_master/gcc/gimple-loop-jam.c:407 0x93ebce tree_loop_unroll_and_jam /testing/gcc/gcc_src_master/gcc/gimple-loop-jam.c:551 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. gcc version 12.0.0 20211121 (8fef6f720a5a0a056abfa986ba870bb406ab4716) (GCC)
Thanks for the report, started with r12-3677-gf92901a508305f29
I will have a look.
OK, so I think this is an overflow somewhere in data dependence compute ... Creating dr for MEM <short unsigned int[<unknown>]> [(const short unsigned int &)&c][_2] analyze_innermost: success. base_address: &c offset from base address: (ssizetype) ((sizetype) h_10 * 2) constant offset from base address: 0 step: -3762939935406616984(OVF) base alignment: 2 base misalignment: 0 offset alignment: 2 step alignment: 8 base_object: MEM <short unsigned int[<unknown>]> [(const short unsigned int &)&c] Access function 0: {{0, +, 3}_1, +, 7341902069151467316}_2 ... (Data Dep: #(Data Ref: # bb: 4 # stmt: _25 = MEM <short unsigned int[<unknown>]> [(const short unsigned int &)&c][_2]; # ref: MEM <short unsigned int[<unknown>]> [(const short unsigned int &)&c][_2]; # base_object: MEM <short unsigned int[<unknown>]> [(const short unsigned int &)&c]; # Access function 0: {{0, +, 3}_1, +, 7341902069151467316}_2 #) #(Data Ref: # bb: 5 # stmt: pretmp_28 = MEM[(const short unsigned int &)_3]; # ref: MEM[(const short unsigned int &)_3]; # base_object: MEM[(const short unsigned int &)&c]; # Access function 0: {{0B, +, 6}_1, +, 14683804138302934632}_2 #) access_fn_A: {{0B, +, 6}_1, +, 14683804138302934632}_2 access_fn_B: {{0B, +, 6}_1, +, 14683804138302934632}_2 (subscript iterations_that_access_an_element_twice_in_A: [0] last_conflict: scev_not_known iterations_that_access_an_element_twice_in_B: [0] last_conflict: scev_not_known (Subscript distance: 0 )) loop nest: (1 2 ) distance_vector: 0 0 distance_vector: -1736083252 3 direction_vector: = = direction_vector: - + ) the accesses are equal so the distance vector should be 0 0 which it is for the inner loop but not for the outer it seems(!?). We run into if (same_access_functions (ddr)) { /* Save the 0 vector. */ dist_v = lambda_vector_new (DDR_NB_LOOPS (ddr)); save_dist_v (ddr, dist_v); if (invariant_access_functions (ddr, loop_nest->num)) add_distance_for_zero_overlaps (ddr); if (DDR_NB_LOOPS (ddr) > 1) add_other_self_distances (ddr); return true; where invariant_access_functions is false and we eventually run into add_multivariate_self_dist. Ah, so the issue is lambda vector dumping is broken (truncates to int) and unroll-and-jam also fails to use lambda_int ...
The issue is latent since lambda_int became HOST_WIDE_INT which happened in GCC 9.
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:6cd440670078af89d82cbb67e01a5ecec8eec238 commit r12-5468-g6cd440670078af89d82cbb67e01a5ecec8eec238 Author: Richard Biener <rguenther@suse.de> Date: Tue Nov 23 10:11:41 2021 +0100 tree-optimization/103361 - fix unroll-and-jam direction vector handling This properly uses lambda_int instead of truncating the direction vector to int which leads to false unexpected negative values. 2021-11-23 Richard Biener <rguenther@suse.de> PR tree-optimization/103361 * gimple-loop-jam.c (adjust_unroll_factor): Use lambda_int for the dependence distance. * tree-data-ref.c (print_lambda_vector): Properly print a lambda_int. * g++.dg/torture/pr103361.C: New testcase.
Fixed on trunk sofar, queued for backporting.
The releases/gcc-11 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:d2f4753d4ff0edf944281cc2e4d5b5b91a9f14c9 commit r11-9583-gd2f4753d4ff0edf944281cc2e4d5b5b91a9f14c9 Author: Richard Biener <rguenther@suse.de> Date: Tue Nov 23 10:11:41 2021 +0100 tree-optimization/103361 - fix unroll-and-jam direction vector handling This properly uses lambda_int instead of truncating the direction vector to int which leads to false unexpected negative values. 2021-11-23 Richard Biener <rguenther@suse.de> PR tree-optimization/103361 * gimple-loop-jam.c (adjust_unroll_factor): Use lambda_int for the dependence distance. * tree-data-ref.c (print_lambda_vector): Properly print a lambda_int. * g++.dg/torture/pr103361.C: New testcase. (cherry picked from commit 6cd440670078af89d82cbb67e01a5ecec8eec238)
The releases/gcc-10 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:4ed8728e2646897c98826cf43be2e4682d04fc2c commit r10-10548-g4ed8728e2646897c98826cf43be2e4682d04fc2c Author: Richard Biener <rguenther@suse.de> Date: Tue Nov 23 10:11:41 2021 +0100 tree-optimization/103361 - fix unroll-and-jam direction vector handling This properly uses lambda_int instead of truncating the direction vector to int which leads to false unexpected negative values. 2021-11-23 Richard Biener <rguenther@suse.de> PR tree-optimization/103361 * gimple-loop-jam.c (adjust_unroll_factor): Use lambda_int for the dependence distance. * tree-data-ref.c (print_lambda_vector): Properly print a lambda_int. * g++.dg/torture/pr103361.C: New testcase. (cherry picked from commit 6cd440670078af89d82cbb67e01a5ecec8eec238)
The releases/gcc-9 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:d55db847de865ec3a4d7a89c30295924508e1833 commit r9-10042-gd55db847de865ec3a4d7a89c30295924508e1833 Author: Richard Biener <rguenther@suse.de> Date: Tue Nov 23 10:11:41 2021 +0100 tree-optimization/103361 - fix unroll-and-jam direction vector handling This properly uses lambda_int instead of truncating the direction vector to int which leads to false unexpected negative values. 2021-11-23 Richard Biener <rguenther@suse.de> PR tree-optimization/103361 * gimple-loop-jam.c (adjust_unroll_factor): Use lambda_int for the dependence distance. * tree-data-ref.c (print_lambda_vector): Properly print a lambda_int. * g++.dg/torture/pr103361.C: New testcase. (cherry picked from commit 6cd440670078af89d82cbb67e01a5ecec8eec238)
Fixed.