# [llvm-dev] Query on unswitching + vectorization

4 messages
Open this post in threaded view
|

## [llvm-dev] Query on unswitching + vectorization

 Hi,   I am going through analysis on unswitching + vectorization. For the below test, llvm unswitches successfully but fails to vectorize the loop after unswitching. Llvm bails out saying “Found an outside user” apparently which is the value of ‘tmp’.   int i, w, x[1000], y[1000],tmp; void fn() {   for (i = 0; i < 1000; i++) {     if (w==1) {         y[i] = 1; tmp = i*2;     }     else if (w==2) {         y[i] = 2; tmp = i*4;     }     x[i] += y[i] + tmp;   } }   GCC vectorizes the loop after unswitching/if conversion. Request your help in vectorizing this loop.   Regards Ganesh   _______________________________________________ LLVM Developers mailing list [hidden email] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Open this post in threaded view
|

## Re: [llvm-dev] Query on unswitching + vectorization

 On 5/10/2018 10:44 PM, Gopalasubramanian, Ganesh via llvm-dev wrote: Hi,   I am going through analysis on unswitching + vectorization. For the below test, llvm unswitches successfully but fails to vectorize the loop after unswitching. Llvm bails out saying “Found an outside user” apparently which is the value of ‘tmp’.   int i, w, x[1000], y[1000],tmp; void fn() {   for (i = 0; i < 1000; i++) {     if (w==1) {         y[i] = 1; tmp = i*2;     }     else if (w==2) {         y[i] = 2; tmp = i*4;     }     x[i] += y[i] + tmp;   } }   GCC vectorizes the loop after unswitching/if conversion. Request your help in vectorizing this loop.   Looks like some sort of pass ordering issue; it will vectorize if indvars runs sometime between loop unswitch and the vectorizer. -Eli ```-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project``` _______________________________________________ LLVM Developers mailing list [hidden email] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
 Looks like some sort of pass ordering issue; it will vectorize if indvars runs sometime between loop unswitch and the vectorizer.   That insight is helpful. I scheduled Canonicalization of induction variable before loop vectorization and could get the loop vectorized. The indvars are heavily dependent on SCEV. If there a scalar like tmp which is of real type, we may not be able to get the indvars sorted out because of the integer type limitation in SCEV! Is there a way out when we have a scalar float computation that is dependent on induction variable? -Ganesh     From: Friedman, Eli [mailto:[hidden email]] Sent: Saturday, May 12, 2018 12:36 AM To: Gopalasubramanian, Ganesh <[hidden email]>; [hidden email] Subject: Re: [llvm-dev] Query on unswitching + vectorization   On 5/10/2018 10:44 PM, Gopalasubramanian, Ganesh via llvm-dev wrote: Hi,   I am going through analysis on unswitching + vectorization. For the below test, llvm unswitches successfully but fails to vectorize the loop after unswitching. Llvm bails out saying “Found an outside user” apparently which is the value of ‘tmp’.   int i, w, x[1000], y[1000],tmp; void fn() {   for (i = 0; i < 1000; i++) {     if (w==1) {         y[i] = 1; tmp = i*2;     }     else if (w==2) {         y[i] = 2; tmp = i*4;     }     x[i] += y[i] + tmp;   } }   GCC vectorizes the loop after unswitching/if conversion. Request your help in vectorizing this loop.   Looks like some sort of pass ordering issue; it will vectorize if indvars runs sometime between loop unswitch and the vectorizer. -Eli `-- ` `Employee of Qualcomm Innovation Center, Inc.` `Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project` _______________________________________________ LLVM Developers mailing list [hidden email] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
 On 5/14/2018 2:21 AM, Gopalasubramanian, Ganesh wrote: Looks like some sort of pass ordering issue; it will vectorize if indvars runs sometime between loop unswitch and the vectorizer.   That insight is helpful. I scheduled Canonicalization of induction variable before loop vectorization and could get the loop vectorized. The indvars are heavily dependent on SCEV. If there a scalar like tmp which is of real type, we may not be able to get the indvars sorted out because of the integer type limitation in SCEV! Is there a way out when we have a scalar float computation that is dependent on induction variable? In general, a loop can't be vectorized if there's a PHI node; a scalar dependency means the iterations have to run in order.  But there are some special cases for reductions and induction variables.  For the LLVM loop vectorizer, see LoopVectorizationLegality::canVectorizeInstrs. -Eli ```-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project``` _______________________________________________ LLVM Developers mailing list [hidden email] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev