<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101293>101293</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM cannot vectorize and optimize the following case
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
4465464
</td>
</tr>
</table>
<pre>
LLVM cannot vectorize and optimize the following case. LLVM cannot generate SIMD instructions for vectorization optimization in this case.why?
#include <stdlib.h>
struct plan7_s {
int M; /* length of the model (# nodes) +*/
int **tsc; /* transition scores [0.6][1.M-1] -*/
int **msc; /* match emission scores [0.MAXCODE-1][1.M] -*/
int **isc; /* ins emission scores [0.MAXCODE-1][1.M-1] -*/
int xsc[4][2]; /* N,E,C,J transitions -*/
int *bsc; /* begin transitions [1.M] -*/
};
float P7Viterbi(char *dsq, int L, struct plan7_s *hmm)
{
int **xmx;
int **mmx;
int **imx;
int **dmx;
int i,k;
int sc;
int *mc, *dc, *ic; /* pointers to rows of mmx, dmx, imx */
int *ms, *is; /* pointers to msc[i], isc[i] */
int *mpp, *ip; /* ptrs to mmx[i-1], mmx[i], imx[i-1] */
int *bp; /* ptr into bsc[] */
int xmb; /* value of xmx[i-1][0] */
int *dpp; /* ptr into dmx[i-1] (previous row) */
int *tpmm, *tpmi, *tpmd, *tpim, *tpii, *tpdm, *tpdd; /* ptrs into tsc */
int M;
xmx[0][4] = 0; /* S->N, p=1 */
xmx[0][0] = hmm->xsc[0][0]; /* S->N->B, no N-tail */
xmx[0][1] = xmx[0][2] = xmx[0][3] = -987654321; /* need seq to get here */
for (k = 0; k <= hmm->M; k++)
mmx[0][k] = imx[0][k] = dmx[0][k] = -987654321; /* need seq to get here */
/* Initializations that help icc vectorize.
*/
M = hmm->M;
tpmm = hmm->tsc[0];
tpim = hmm->tsc[3];
tpdm = hmm->tsc[5];
tpmd = hmm->tsc[2];
tpdd = hmm->tsc[6];
tpmi = hmm->tsc[1];
tpii = hmm->tsc[4];
bp = hmm->bsc;
for (i = 1; i <= L; i++) {
mc = mmx[i];
dc = dmx[i];
ic = imx[i];
mpp = mmx[i-1];
dpp = dmx[i-1];
ip = imx[i-1];
xmb = xmx[i-1][0];
ms = hmm->msc[(int) dsq[i]];
is = hmm->isc[(int) dsq[i]];
mc[0] = -987654321;
dc[0] = -987654321;
ic[0] = -987654321;
for (k = 1; k <= M; k++) {
mc[k] = mpp[k-1] + tpmm[k-1];
if ((sc = ip[k-1] + tpim[k-1]) > mc[k]) mc[k] = sc;
if ((sc = dpp[k-1] + tpdm[k-1]) > mc[k]) mc[k] = sc;
if ((sc = xmb + bp[k]) > mc[k]) mc[k] = sc;
mc[k] += ms[k];
if (mc[k] < -987654321) mc[k] = -987654321;
dc[k] = dc[k-1] + tpdd[k-1];
if ((sc = mc[k-1] + tpmd[k-1]) > dc[k]) dc[k] = sc;
if (dc[k] < -987654321) dc[k] = -987654321;
if (k < M) {
ic[k] = mpp[k] + tpmi[k];
if ((sc = ip[k] + tpii[k]) > ic[k]) ic[k] = sc;
ic[k] += is[k];
if (ic[k] < -987654321) ic[k] = -987654321;
}
}
}
return (float)sc; /* the total Viterbi score. */
}
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWF2PozoS_TXOi5UIDCThIQ8N6Uiz6syuNNJo31aAnVDbGBjsdGfur7-y-TLEdPe9uv3QgcqpOlXH5a8kQsC1ZOyAgggFx1Vyk3nVHHx_G_hbf5VW9Pfh5eXnGWdJWVYSv7FMVg38wXBSUlzVErh6kTnDl6ooqncorzhLBNtg0-3KStYkkuEf385HDKWQzS2TUJUCX6pmiJooUx-1fYESyxxEG_M9_42eTyiKUXhCzhE5T5b_xIMyK26UYeTFQtIC0k2OvGcT1PLjukjK3f8ERruotWMMpcTq74y8CFv-EDkh8oQLVl5ljquLLp1XlBUYkT0iHi4rygQi4egRIfKk_EwKbXqSIrPzdDSySUoBWgiRVQ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