Skip to content

Commit 97ae616

Browse files
committed
Improve vectorization with conditionals around sin/cos
Recognize a loop with half-size predicate conditional and body computation using sin or cosine intrinsics. This change provides enhanced capabilities for such loops. Previously we tried to prevent vectorization due to the nature of sin/cos handling, and now these loops correctly vectorize.
1 parent a66d802 commit 97ae616

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tools/flang2/flang2exe/cgmain.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7473,10 +7473,21 @@ gen_llvm_vsincos_call(int ilix)
74737473
char sincosName[36]; /* make_math_name buffer is 32 */
74747474
int vecLen = vecTy->sub_elements;
74757475
int opndCount = ili_get_vect_arg_count(ilix);
7476+
int mask_arg_ili = ILI_OPND(ilix, opndCount - 1);
74767477
bool hasMask = false;
7478+
74777479
/* Mask operand is always the one before the last operand */
7478-
if (ILI_OPC(ILI_OPND(ilix, opndCount - 1)) != IL_NULL) {
7479-
opnd->next = gen_llvm_expr(ILI_OPND(ilix, opndCount - 1), vecTy);
7480+
if (ILI_OPC(mask_arg_ili) != IL_NULL) {
7481+
if((ILI_OPC(mask_arg_ili) == IL_VPERMUTE ||
7482+
(ILI_OPC(mask_arg_ili) == IL_VNOT &&
7483+
ILI_OPC(ILI_OPND(mask_arg_ili, 1)) == IL_VPERMUTE)) &&
7484+
internal_masked_intrinsic) {
7485+
internal_masked_intrinsic = false;
7486+
opnd->next = gen_llvm_expr(mask_arg_ili, vecTy);
7487+
internal_masked_intrinsic = true;
7488+
}
7489+
else
7490+
opnd->next = gen_llvm_expr(mask_arg_ili, vecTy);
74807491
hasMask = true;
74817492
}
74827493
llmk_math_name(sincosName, MTH_sincos, vecLen, hasMask, dtypeName);

0 commit comments

Comments
 (0)