On 12/14/21 11:28, Jakub Jelinek wrote:
Wouldn't this be better done only if field_val has the msb set

Yes, updated in the attached patch.

and keep the CONVERT_EXPR otherwise (why isn't it NOP_EXPR?)?

Dunno, but I can prepare a separate patch (likely stage1 material,
right)? Note that are other places that also use CONVERT_EXPR.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin
From 227450e9f3a506fdfcff67aa45135fe31f3f91f6 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Mon, 13 Dec 2021 15:34:30 +0100
Subject: [PATCH] i386: Fix emissing of __builtin_cpu_supports.

	PR target/103661

gcc/ChangeLog:

	* config/i386/i386-builtins.c (fold_builtin_cpu): Compare to 0
	as API expects that non-zero values are returned (do that
	it mask == 31).
	For "avx512vbmi2" argument, we return now 1 << 31, which is a
	negative integer value.
---
 gcc/config/i386/i386-builtins.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
index 0fb14b55712..bca244fc011 100644
--- a/gcc/config/i386/i386-builtins.c
+++ b/gcc/config/i386/i386-builtins.c
@@ -2353,7 +2353,11 @@ fold_builtin_cpu (tree fndecl, tree *args)
       /* Return __cpu_model.__cpu_features[0] & field_val  */
       final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt,
 		      build_int_cstu (unsigned_type_node, field_val));
-      return build1 (CONVERT_EXPR, integer_type_node, final);
+      if (isa_names_table[i].feature == 31)
+	return build2 (NE_EXPR, integer_type_node, final,
+		       build_int_cst (unsigned_type_node, 0));
+      else
+	return build1 (CONVERT_EXPR, integer_type_node, final);
     }
   gcc_unreachable ();
 }
-- 
2.34.1

Reply via email to