public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Tobias Burnus <tobias@codesourcery.com>
Subject: [committed] openmp: Map holds clause to IFN_ASSUME for C/C++
Date: Thu, 6 Oct 2022 10:42:42 +0200	[thread overview]
Message-ID: <Yz6VAi7u7pMLbb4K@tucnak> (raw)

Hi!

Now that [[assume (cond)]] support is in, this simple patch makes
  #pragma omp assume holds(cond)
use it.

Committed to trunk.

2022-10-06  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.cc (c_parser_omp_assumption_clauses): Emit IFN_ASSUME
	call for holds clause on assume construct.

	* parser.cc (cp_parser_omp_assumption_clauses): Emit IFN_ASSUME
	call for holds clause on assume construct.

	* c-c++-common/gomp/assume-4.c: New test.

--- gcc/c/c-parser.cc.jj	2022-10-06 08:56:28.570128568 +0200
+++ gcc/c/c-parser.cc	2022-10-06 10:07:25.596420330 +0200
@@ -23571,10 +23571,12 @@ c_parser_omp_assumption_clauses (c_parse
 	      tree t = convert_lvalue_to_rvalue (eloc, expr, true, true).value;
 	      t = c_objc_common_truthvalue_conversion (eloc, t);
 	      t = c_fully_fold (t, false, NULL);
-	      if (is_assume)
+	      if (is_assume && t != error_mark_node)
 		{
-		  /* FIXME: Emit .ASSUME (t) call here.  */
-		  (void) t;
+		  tree fn = build_call_expr_internal_loc (eloc, IFN_ASSUME,
+							  void_type_node, 1,
+							  t);
+		  add_stmt (fn);
 		}
 	      parens.skip_until_found_close (parser);
 	    }
--- gcc/cp/parser.cc.jj	2022-10-06 08:56:28.625127823 +0200
+++ gcc/cp/parser.cc	2022-10-06 10:20:35.452732109 +0200
@@ -46023,13 +46023,15 @@ cp_parser_omp_assumption_clauses (cp_par
 	  matching_parens parens;
 	  if (parens.require_open (parser))
 	    {
+	      location_t eloc = cp_lexer_peek_token (parser->lexer)->location;
 	      tree t = cp_parser_assignment_expression (parser);
 	      if (!type_dependent_expression_p (t))
 		t = contextual_conv_bool (t, tf_warning_or_error);
-	      if (is_assume)
+	      if (is_assume && !error_operand_p (t))
 		{
-		  /* FIXME: Emit .ASSUME (t) call here.  */
-		  (void) t;
+		  t = build_call_expr_internal_loc (eloc, IFN_ASSUME,
+						    void_type_node, 1, t);
+		  finish_expr_stmt (t);
 		}
 	      if (!parens.require_close (parser))
 		cp_parser_skip_to_closing_parenthesis (parser,
--- gcc/testsuite/c-c++-common/gomp/assume-4.c.jj	2022-10-06 10:17:58.028862432 +0200
+++ gcc/testsuite/c-c++-common/gomp/assume-4.c	2022-10-06 10:23:41.011221059 +0200
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "return 42;" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "return -1;" "optimized" } } */
+
+int
+foo (int x)
+{
+  int y;
+  #pragma omp assume holds (x == 42)
+  y = x;
+  return y;
+}
+
+int
+bar (int x)
+{
+  #pragma omp assume holds (x < 42)
+  ;
+  if (x == 42)
+    return -1;
+  return 42;
+}

	Jakub


                 reply	other threads:[~2022-10-06  8:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yz6VAi7u7pMLbb4K@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).