aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-01-10 14:13:25 +0100
committerRichard Biener <rguenther@suse.de>2024-01-10 15:21:37 +0100
commitcac9d2d2346bf06b29b34e12cf0a005c37eacdc9 (patch)
tree2d107d2759fd1a4a4f3fa575b17e28099f8f3668 /gcc/tree-vect-loop.cc
parentf8a70fb21767883f6d3c13e22be8d307dd98f342 (diff)
downloadgcc-cac9d2d2346bf06b29b34e12cf0a005c37eacdc9.zip
gcc-cac9d2d2346bf06b29b34e12cf0a005c37eacdc9.tar.gz
gcc-cac9d2d2346bf06b29b34e12cf0a005c37eacdc9.tar.bz2
tree-optimization/113078 - conditional subtraction reduction vectorization
When if-conversion was changed to use .COND_ADD/SUB for conditional reduction it was forgotten to update reduction path handling to canonicalize .COND_SUB to .COND_ADD for vectorizable_reduction similar to what we do for MINUS_EXPR. The following adds this and testcases exercising this at runtime and looking for the appropriate masked subtraction in the vectorized code on x86. PR tree-optimization/113078 * tree-vect-loop.cc (check_reduction_path): Canonicalize .COND_SUB to .COND_ADD. * gcc.dg/vect/vect-reduc-cond-sub.c: New testcase. * gcc.target/i386/vect-pr113078.c: Likewise.
Diffstat (limited to 'gcc/tree-vect-loop.cc')
-rw-r--r--gcc/tree-vect-loop.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c5b2799..1bdad0f 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -4116,6 +4116,13 @@ pop:
if (op.ops[1] == op.ops[opi])
neg = ! neg;
}
+ else if (op.code == IFN_COND_SUB)
+ {
+ op.code = IFN_COND_ADD;
+ /* Track whether we negate the reduction value each iteration. */
+ if (op.ops[2] == op.ops[opi])
+ neg = ! neg;
+ }
if (CONVERT_EXPR_CODE_P (op.code)
&& tree_nop_conversion_p (op.type, TREE_TYPE (op.ops[0])))
;