]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Map holds clause to IFN_ASSUME for C/C++
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Oct 2022 08:39:41 +0000 (10:39 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 6 Oct 2022 08:39:41 +0000 (10:39 +0200)
Now that [[assume (cond)]] support is in, this simple patch makes
  #pragma omp assume holds(cond)
use it.

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
gcc/cp/parser.cc
gcc/testsuite/c-c++-common/gomp/assume-4.c [new file with mode: 0644]

index 9b7663739dde508c2a633d4e5d4b94369b5a13af..67b919c0b181b50d91f3a286f19fe2a728ce417a 100644 (file)
@@ -23571,10 +23571,12 @@ c_parser_omp_assumption_clauses (c_parser *parser, bool is_assume)
              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);
            }
index baa808a4634b15e0b28f793d5dd23136772f6133..90e06f914fb1373b0d41f9b88d5d057583d746fb 100644 (file)
@@ -46023,13 +46023,15 @@ cp_parser_omp_assumption_clauses (cp_parser *parser, cp_token *pragma_tok,
          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,
diff --git a/gcc/testsuite/c-c++-common/gomp/assume-4.c b/gcc/testsuite/c-c++-common/gomp/assume-4.c
new file mode 100644 (file)
index 0000000..9da2296
--- /dev/null
@@ -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;
+}