From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8E733857C56; Wed, 13 Mar 2024 10:20:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8E733857C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710325200; bh=lHz99dKxgokpIYjs+hqn0uYUaUkZYm049eGeOHpFUdI=; h=From:To:Subject:Date:From; b=YfH/cxcvGQYxDRte+g/GzrlxCXJ7eWbpHMF3A1fKrSB39bUIv+ARGUYiOZyNzMH5X 5DtshPY9jX8HoW/+MaUhuyDY3/6f7W5WuqXH/eU0dLMqDg6MLfTIWEBXbi4kpXDMSf IeyBaEbrPUbH9K9fNrJVJfEsifDTooqfVkIMlXGU= From: "hliu at amperecomputing dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114322] New: [14 Regression] SCEV analysis failed for bases like A[(i+x)*stride] since r14-9193-ga0b1798042d033 Date: Wed, 13 Mar 2024 10:19:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hliu at amperecomputing dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114322 Bug ID: 114322 Summary: [14 Regression] SCEV analysis failed for bases like A[(i+x)*stride] since r14-9193-ga0b1798042d033 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hliu at amperecomputing dot com Target Milestone: --- Compile the following case with: gcc simp.c -Ofast -mcpu=3Dneoverse-n1 -S \ -fdump-tree-ifcvt -fdump-tree-vect-details-scev int foo (short *A, int x, int stride) { int sum =3D 0; if (stride > 1) { #pragma GCC unroll 1 for (int i =3D 0; i < 1024; ++i) sum +=3D A[(i + x) * stride]; } return sum; } The gimple in the loop is: : # sum_19 =3D PHI # i_20 =3D PHI # ivtmp_37 =3D PHI _1 =3D x_12(D) + i_20; _2 =3D _1 * stride_11(D); _3 =3D (long unsigned int) _2; _4 =3D _3 * 2; _5 =3D A_13(D) + _4; _6 =3D *_5; _7 =3D (int) _6; sum_15 =3D _7 + sum_19; Before the commit (i.e., from pr114074 bug fix), it can be vectorized: Creating dr for *_5 analyze_innermost: (analyze_scalar_evolution=20 (loop_nb =3D 1) (scalar =3D _5) (get_scalar_evolution=20 (scalar =3D _5) (scalar_evolution =3D {A_13(D) + (long unsigned int) (stride_11(D) * x_12= (D)) * 2, +, (long unsigned int) stride_11(D) * 2}_1)) ) success. (analyze_scalar_evolution=20 (loop_nb =3D 1) (scalar =3D _5) (get_scalar_evolution=20 (scalar =3D _5) (scalar_evolution =3D {A_13(D) + (long unsigned int) (stride_11(D) * x_12= (D)) * 2, +, (long unsigned int) stride_11(D) * 2}_1)) ) (instantiate_scev=20 (instantiate_below =3D 5 -> 3) (evolution_loop =3D 1) (chrec =3D {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) * 2, +, (long unsigned int) stride_11(D) * 2}_1) (res =3D {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) * 2, +, = (long unsigned int) stride_11(D) * 2}_1)) base_address: A_13(D) + (sizetype) (stride_11(D) * x_12(D)) * 2 offset from base address: 0 constant offset from base address: 0 step: (ssizetype) ((long unsigned int) stride_11(D) * 2) base alignment: 2 base misalignment: 0 offset alignment: 128 step alignment: 2 base_object: *A_13(D) + (sizetype) (stride_11(D) * x_12(D)) * 2 Access function 0: {0B, +, (long unsigned int) stride_11(D) * 2}_1 After the commit, loop vectorized failed due to SCEV failure with *_5: Creating dr for *_5 analyze_innermost: (analyze_scalar_evolution=20 (loop_nb =3D 1) (scalar =3D _5) (get_scalar_evolution=20 (scalar =3D _5) (scalar_evolution =3D _5)) ) (analyze_scalar_evolution=20 (loop_nb =3D 1) (scalar =3D _5) (get_scalar_evolution=20 (scalar =3D _5) (scalar_evolution =3D _5)) ) simp.c:11:10: missed: failed: evolution of base is not affine. .. (res =3D scev_not_known)) To my understanding, '(i + x) * stride' is signed integer calculation, in w= hich overflow is undefined behavior and the case should be vectorized.=