[gcc(refs/users/aoliva/heads/testme)] [PR103149] harden conditionals detach through mem if general regs won't do
Alexandre Oliva
aoliva@gcc.gnu.org
Fri Dec 3 03:11:12 GMT 2021
https://gcc.gnu.org/g:7526057fabd3395f1985f3016d7bb7d02200fb3e
commit 7526057fabd3395f1985f3016d7bb7d02200fb3e
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Dec 2 23:43:47 2021 -0300
[PR103149] harden conditionals detach through mem if general regs won't do
Diff:
---
gcc/gimple-harden-conditionals.cc | 17 +++++++++--
gcc/testsuite/gcc.target/aarch64/pr103149.c | 13 ++++++++
gcc/testsuite/gcc.target/riscv/pr103302.c | 47 +++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc
index cfa2361d65b..2ebd2ff4387 100644
--- a/gcc/gimple-harden-conditionals.cc
+++ b/gcc/gimple-harden-conditionals.cc
@@ -132,13 +132,26 @@ detach_value (location_t loc, gimple_stmt_iterator *gsip, tree val)
tree ret = make_ssa_name (TREE_TYPE (val));
SET_SSA_NAME_VAR_OR_IDENTIFIER (ret, SSA_NAME_IDENTIFIER (val));
- /* Output asm ("" : "=g" (ret) : "0" (val)); */
+ bool need_memory = true;
+ enum machine_mode mode = TYPE_MODE (TREE_TYPE (val));
+ if (mode != BLKmode)
+ for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+ if (TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], i)
+ && targetm.hard_regno_mode_ok (i, mode))
+ {
+ need_memory = false;
+ break;
+ }
+
+ const char *constraint = need_memory ? "=m" : "=g";
+
+ /* Output asm ("" : "=[gm]" (ret) : "0" (val)); */
vec<tree, va_gc> *inputs = NULL;
vec<tree, va_gc> *outputs = NULL;
vec_safe_push (outputs,
build_tree_list
(build_tree_list
- (NULL_TREE, build_string (2, "=g")),
+ (NULL_TREE, build_string (2, constraint)),
ret));
vec_safe_push (inputs,
build_tree_list
diff --git a/gcc/testsuite/gcc.target/aarch64/pr103149.c b/gcc/testsuite/gcc.target/aarch64/pr103149.c
new file mode 100644
index 00000000000..e7283b4f569
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr103149.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=armv8-a+sve -O2 -fharden-conditional-branches -fno-tree-scev-cprop" } */
+
+/* -fharden-conditional-branches relies on ASMNESIA, that used to require
+ GENERAL_REGS even for vectorized booleans, which can't go on
+ GENERAL_REGS. */
+
+void
+foo (int *p)
+{
+ while (*p < 1)
+ ++*p;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/pr103302.c b/gcc/testsuite/gcc.target/riscv/pr103302.c
new file mode 100644
index 00000000000..822c4087416
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr103302.c
@@ -0,0 +1,47 @@
+/* { dg-do run } */
+/* { dg-options "-Og -fharden-compares -fno-tree-dce -fno-tree-fre " } */
+
+typedef unsigned char u8;
+typedef unsigned char __attribute__((__vector_size__ (32))) v256u8;
+typedef unsigned short __attribute__((__vector_size__ (32))) v256u16;
+typedef unsigned short __attribute__((__vector_size__ (64))) v512u16;
+typedef unsigned int u32;
+typedef unsigned int __attribute__((__vector_size__ (4))) v512u32;
+typedef unsigned long long __attribute__((__vector_size__ (32))) v256u64;
+typedef unsigned long long __attribute__((__vector_size__ (64))) v512u64;
+typedef unsigned __int128 __attribute__((__vector_size__ (32))) v256u128;
+typedef unsigned __int128 __attribute__((__vector_size__ (64))) v512u128;
+
+v512u16 g;
+
+void
+foo0 (u8 u8_0, v256u16 v256u16_0, v512u16 v512u16_0, u32 u32_0, v512u32,
+ v256u64 v256u64_0, v512u64 v512u64_0, v256u128 v256u128_0,
+ v512u128 v512u128_0)
+{
+ u32_0 <= (v512u128) (v512u128_0 != u8_0);
+ v512u64 v512u64_1 =
+ __builtin_shufflevector (v256u64_0, v512u64_0, 7, 8, 0, 9, 5, 0, 3, 1);
+ g = v512u16_0;
+ (v256u8) v256u16_0 + (v256u8) v256u128_0;
+}
+
+int
+main (void)
+{
+ foo0 (40, (v256u16)
+ {
+ }, (v512u16)
+ {
+ }, 0, (v512u32)
+ {
+ }, (v256u64)
+ {
+ }, (v512u64)
+ {
+ }, (v256u128)
+ {
+ }, (v512u128)
+ {
+ });
+}
More information about the Gcc-cvs
mailing list