<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi, <br><br>This patch is for radar 18144665 which is exposed by Machael Z's commit. We will get an assertion if enabling the vectorization of GEP with multiple-uses on this case:<br><br><span style="font-family: Menlo; font-size: 11px;">fn2() {</span><br><span style="font-family: Menlo; font-size: 11px;"> a[11] = a + 11;</span><br><span style="font-family: Menlo; font-size: 11px;"> a[12] = a + 56;</span><br><span style="font-family: Menlo; font-size: 11px;">}</span><br><br>The reason of this bug is that our current framework assumes that all
in-tree scalars will eventually become vectors so all in-tree uses do
not need extract. However, it is not the case for vector instructions
that has scalar operands; the scalar operands will remain scalar and we
still need the extract. For example in this test case:<br><br> %0 = load i64** @a, align 8, !tbaa !1<br> %add.ptr1 = getelementptr inbounds i64* %0, i64 56 // A<br> %add.ptr = getelementptr inbounds i64* %0, i64 11 // B<br> %1 = insertelement <2 x i64*> undef, i64* %0, i32 0<br> %2 = insertelement <2 x i64*> %1, i64* %0, i32 1<br> %3 = getelementptr <2 x i64*> %2, <2 x i64> <i64 11, i64 56> // C: Vectorized Value<br> %4 = ptrtoint <2 x i64*> %3 to <2 x i64><br> %arrayidx2 = getelementptr inbounds i64* %0, i64 12<br> %5 = bitcast i64* %add.ptr to <2 x i64>* // D<br> store <2 x i64> %4, <2 x i64>* %5, align 8, !tbaa !5<br> ret i32 undef<br><br>Now Our framework vectorizes A and B to C. add.ptr(A) is used by D as
the pointer operand. Although it is in-tree uses, we still need to
extract this value from C.<br><br>So here is my proposal in my patch to solve this:<br>1) When we build ExternalUses List, we need to find out if the in-tree
use needs extract instead of ignoring all of them. It will help us to
make the cost model right.<br>2) When we vectorize load and store, currently we will generate bitcast
to transfer pointer operand. Now we need to add this bitcast to
ExternalUses List and tell the SLP-vectorizer to extract the value. <br><br>By applying this patch, we can re-enable the vectorization of GEP with multiple-uses. Any comment is appreciated. <br> <br><div><br></div><div><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div></div></blockquote></div></body></html>