From 1260d19905063540e560bda4924f09f1aff4bed5 Mon Sep 17 00:00:00 2001 From: Will Schmidt Date: Thu, 13 Jul 2017 14:09:12 +0000 Subject: [PATCH] rs6000.c (rs6000_gimple_fold_builtin): Return early if there is no lhs. [gcc] 2017-07-12 Will Schmidt * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Return early if there is no lhs. [testsuite] 2017-07-12 Will Schmidt * gcc.target/powerpc/fold-vec-missing-lhs: New. From-SVN: r250185 --- gcc/ChangeLog | 5 ++++ gcc/config/rs6000/rs6000.c | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ .../gcc.target/powerpc/fold-vec-missing-lhs.c | 24 +++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/fold-vec-missing-lhs.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3246378038b..2a4f0827e8f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ + 2017-07-13 Will Schmidt + + * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Return + early if there is no lhs. + 2017-07-13 Martin Liska * dwarf2out.c (gen_pointer_type_die): Remove dead code. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index af5b5f1a2f6..a114d612162 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -16302,6 +16302,10 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl); tree arg0, arg1, lhs; + /* Generic solution to prevent gimple folding of code without a LHS. */ + if (!gimple_call_lhs (stmt)) + return false; + switch (fn_code) { /* Flavors of vec_add. We deliberately don't expand diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b5ca7fa348f..b24aab8ccc7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ + 2017-07-13 Will Schmidt + + * gcc.target/powerpc/fold-vec-missing-lhs.c: New. + 2017-07-13 Martin Liska * c-c++-common/ubsan/sanitize-all-1.c: Update scanned pattern. diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-missing-lhs.c b/gcc/testsuite/gcc.target/powerpc/fold-vec-missing-lhs.c new file mode 100644 index 00000000000..6add9038288 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-missing-lhs.c @@ -0,0 +1,24 @@ +/* This test is meant to verify that the gimple-folding does not + occur when the LHS portion of an expression is missing. + The intent of this test is to verify that we do not generate an ICE. + This was noticed during debug of PR81317. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec" } */ + +#include + +vector signed short +test1_nolhs (vector bool short x, vector signed short y) +{ + vec_add (x, y); + return vec_add (x, y); +} + +vector signed short +test2_nolhs (vector signed short x, vector bool short y) +{ + vec_add (x, y); + return vec_add (x, y); +} -- 2.30.2