This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC, patch] An attempt to fix PR tree-optimization/33833 ICE in build2_stat, at tree.c:3110


Hi,

The testcase in PR 33833 ICEs when we try to build data-ref's BASE+INIT
expression as following:

         inner_base = build_fold_indirect_ref (fold_build2 (PLUS_EXPR,
TREE_TYPE (base), base, init));
(in vect_analyze_data_refs, at tree-vect-analyze.c:3291)

PLUS_EXPR is not replaced with POINTER_PLUS_EXPR automatically in
fold_binary() and we fail on gcc_assert that the arguments of PLUS_EXPR
must be INTEGER_CSTs (build2_stat, at tree.c:3110).

If we use POINTER_PLUS_EXPR, i.e.,

         inner_base = build_fold_indirect_ref (fold_build2
(POINTER_PLUS_EXPR,  TREE_TYPE (base), base, init));

the above ICE does not occur, but we fail on other vectorization testcases
in build2_stat, at tree.c:3115 on the check that the conversion (from
ssizetype) to sizetype is not useless, as required by POINTER_PLUS_EXPR.

Converting to sizetype solves both the ICE in the PR and the testsuite
failures:

      inner_base = build_fold_indirect_ref (fold_build2 (POINTER_PLUS_EXPR,
TREE_TYPE (base), base, fold_convert (sizetype, init)));

(and this is what the attached patch does).

The problem is I don't know if the conversion of data-ref's init or offset
to unsigned type is correct. AFAIU, both init and offset can be negative
(and this is the reason why they are ssizetype). However, Pointer Plus
patch already converts offset and init to sizetype:

Index: tree-vect-transform.c
===================================================================
*** tree-vect-transform.c            (.../trunk/gcc)         (revision
125658)
--- tree-vect-transform.c            (.../branches/pointer_plus/gcc)
 (revision 125672)
*************** vect_create_addr_base_for_vector_ref (tr
*** 635,640 ****
--- 635,641 ----

    /* Create base_offset */
    base_offset = size_binop (PLUS_EXPR, base_offset, init);
+   base_offset = fold_convert (sizetype, base_offset);
    dest = create_tmp_var (TREE_TYPE (base_offset), "base_off");
    add_referenced_var (dest);
    base_offset = force_gimple_operand (base_offset, &new_stmt, false,
dest);
*************** vect_create_addr_base_for_vector_ref (tr
*** 663,669 ****
      }

    /* base + base_offset */
!   addr_base = fold_build2 (PLUS_EXPR, TREE_TYPE (data_ref_base),
data_ref_base,
                                        base_offset);

    vect_ptr_type = build_pointer_type (STMT_VINFO_VECTYPE (stmt_info));
--- 664,670 ----
      }

    /* base + base_offset */
!   addr_base = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (data_ref_base),
data_ref_base,
                                        base_offset);

    vect_ptr_type = build_pointer_type (STMT_VINFO_VECTYPE (stmt_info));


Is this O.K.? If yes, I guess, the attached patch must be correct as well
(it was bootstrapped and tested on x86_64-linux).

Thanks,
Ira

(See attached file: pr33833.txt)

Attachment: pr33833.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]