On Sun, Mar 22, 2020 at 11:13 PM qianchao <qianch...@huawei.com> wrote: > > Hi > > The attached testcase triggers ICE when testing GCC trunk on aarch64 with -S > -O2 -ftree-loop-vectorize -march=armv8.2-a+sve -msve-vector-bits=256. > > Before the forwprop pass, we have two gimple statements as follows: > > _43 = &MEM[base: _5, offset: 0B]; > vect__2.7_24 = MEM <vector(8) int> [(int *)_43]; > > The forwprop pass tries to forward propgate the &MEM[base: _5, offset: 0B] to > the base of the MEM <vector(8) int> [(int *)_43]. Thus, we get a gimple > statement as follows: > > vect__2.7_24 = MEM <vector(8) int> [(int *)&MEM[base: _5, offset: 0B]];
This should have simplified to: MEM <vector(8) int> [base: _5, offset: 0B]; And not generate the invalid MEM Of an address expression of a MEM. > > As the &MEM[base: _5, offset: 0B] is a ADDR_EXPR as well as a invalid address > for gimple MEM_REF, ICE triggers in function maybe_canonicalize_mem_ref_addr > at gcc/gimple-fold.c:4899 as follows: > > gcc_checking_assert (TREE_CODE (TREE_OPERAND (*t, 0)) == DEBUG_EXPR_DECL > || is_gimple_mem_ref_addr (TREE_OPERAND (*t, 0))); > > where *t is the MEM <vector(8) int> [(int *)&MEM[base: _5, offset: 0B]] at > that time. > > A simple solution is to add a check before forward propgating a ADDR_EXPR to > a MEM_REF. No that is wrong, the transformation is correct, just a missing folding. Thanks, Andrew Pinski > > Attached please find the proposed patch. > > Newly add test fail without the patch and pass after applying the patch. > > Bootstrap and tested on aarch64 and x86 Linux platform. No new regression > witnessed. > > Any suggestion? > Thanks, > Qian Chao > > Log: > +2020-03-23 Qian chao <qianch...@huawei.com> > + > + PR c/94266 > + * gcc/tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Add check > before forward propgating ADDR_EXPR to the operand of MEM_REF. > > gcc/testsuite: > +2020-03-23 Qian chao <qianch...@huawei.com> > + > + PR c/94266 > + * gcc.target/aarch64/pr94266.c:New test.