https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111407

            Bug ID: 111407
           Summary: ICE: SSA corruption due to widening_mul opt on
                    conflict across an abnormal edge
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

this bug was originally reported against GCC8.5 with profiling feedback. 
there were multiple similar failures due to this issue for our large
application. 

Although we reduced the testing case to a very small size, and changed the
variable names. the failure can only be repeated with -fprofile-use and the
.gcda files. As a result, we cannot expose the testing case.

With the small testing case, and debugging into GCC8, I finally locate the
issue is:

this is a bug in tree-ssa-math-opts.cc, when applying the widening mul
optimization, 
The compiler needs to check whether the operand is in a ABNORMAL PHI, if YES,
we should avoid the transformation.

the following patch against GCC8 can fix the failure very well:

diff -u -r -N -p gcc-8.5.0-20210514-org/gcc/tree-ssa-math-opts.c
gcc-8.5.0-20210514/gcc/tree-ssa-math-opts.c
--- gcc-8.5.0-20210514-org/gcc/tree-ssa-math-opts.c 2023-09-11
21:04:17.891403319 +0000
+++ gcc-8.5.0-20210514/gcc/tree-ssa-math-opts.c 2023-09-13 15:35:44.962336530
+0000
@@ -2346,6 +2346,14 @@ convert_mult_to_widen (gimple *stmt, gim
if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2))
return false;

+ /* if any one of rhs1 and rhs2 is subjust to abnormal coalescing
+ * avoid the tranform. */ 
+ if ((TREE_CODE (rhs1) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
+ || (TREE_CODE (rhs2) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)))
+ return false;
+
to_mode = SCALAR_INT_TYPE_MODE (type);
from_mode = SCALAR_INT_TYPE_MODE (type1);
if (to_mode == from_mode)

I checked the latest upstream GCC14, and found that the function
"convert_mult_to_widen" has the same issue, need to be patched as well.

Reply via email to