From 4bcded23eb87c55a1a3fcd23d5629a0c35aee4ba Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 30 Nov 2020 10:41:36 +0100 Subject: [PATCH] tree-optimization/98048 - fix vector lowering of ABSU_EXPR This makes sure to use the correct type for the LHS of the scalar replacement statement. 20220-11-30 Richard Biener PR tree-optimization/98048 * tree-vect-generic.c (expand_vector_operations_1): Use the correct type for the scalar LHS replacement. * gcc.dg/vect/pr98048.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr98048.c | 14 ++++++++++++++ gcc/tree-vect-generic.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr98048.c diff --git a/gcc/testsuite/gcc.dg/vect/pr98048.c b/gcc/testsuite/gcc.dg/vect/pr98048.c new file mode 100644 index 0000000..e61a376 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr98048.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +extern short var_0; +extern int var_3; +extern int arr_277[]; +int a(int b, int c) { return b < c ? b : c; } +int e; +void test() +{ + e = var_0; + for (int d = 0; d < 9; d++) + if (var_3) + arr_277[d] = a(var_0, -var_0); +} diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c index 23bc1cb..55cf0d9 100644 --- a/gcc/tree-vect-generic.c +++ b/gcc/tree-vect-generic.c @@ -2089,7 +2089,7 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi, if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != CODE_FOR_nothing) { - tree slhs = make_ssa_name (TREE_TYPE (srhs1)); + tree slhs = make_ssa_name (TREE_TYPE (TREE_TYPE (lhs))); gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2); gsi_insert_before (gsi, repl, GSI_SAME_STMT); gimple_assign_set_rhs_from_tree (gsi, -- 2.7.4