Author: Mircea Trofin
Date: 2020-12-15T07:16:54-08:00
New Revision: e2dc306b1ac71258e6ce40a66e778527f282c355

URL: 
https://github.com/llvm/llvm-project/commit/e2dc306b1ac71258e6ce40a66e778527f282c355
DIFF: 
https://github.com/llvm/llvm-project/commit/e2dc306b1ac71258e6ce40a66e778527f282c355.diff

LOG: [utils] Fix UpdateTestChecks case where 2 runs differ for last label

Two RUN lines produce outputs that, each, have some common parts and
some different parts. The common parts are checked under label A. The
differing parts are associated to a function and checked under labels B
and C, respectivelly.
When build_function_body_dictionary is called for the first RUN line, it
will attribute the function body to labels A and C. When the second RUN
is passed to build_function_body_dictionary, it sees that the function
body under A is different from what it has. If in this second RUN line,
A were at the end of the prefixes list, A's body is still kept
associated with the first run's function.

When we output the function body (i.e. add_checks), we stop after
emitting for the first prefix matching that function. So we end up with
the wrong function body (first RUN's A-association).

There is no reason to special-case the last label in the prefixes list,
and the fix is to always clear a label association if we find a RUN line
where the body is different.

Differential Revision: https://reviews.llvm.org/D93078

Added: 
    clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
    clang/test/utils/update_cc_test_checks/prefix-never-matches.test
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-1.ll
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-2.ll
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-3.ll
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/prefix-never-matches.ll
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/common-label-different-bodies.test
    
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/prefix-never-matches.test
    
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll
    
llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test

Modified: 
    llvm/utils/UpdateTestChecks/common.py
    llvm/utils/update_test_prefix.py

Removed: 
    


################################################################################
diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp 
b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
new file mode 100644
index 000000000000..75bd5b1249a7
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O0 -o - %s | 
FileCheck %s -check-prefix=A
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O3 -o - %s | 
FileCheck %s -check-prefix=A
+
+int foo(int i ) {
+    return 1;
+}
\ No newline at end of file

diff  --git a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test 
b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
new file mode 100644
index 000000000000..7100377337bc
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
@@ -0,0 +1,6 @@
+# RUN: cp -f %S/Inputs/prefix-never-matches.cpp %t.cpp
+# RUN: %update_cc_test_checks %t.cpp 2>&1 | FileCheck %s
+# RUN: FileCheck --input-file=%t.cpp %s --check-prefix=OUTPUT
+
+# CHECK: WARNING: Prefix A had conflicting output
+# OUTPUT-NOT: A:
\ No newline at end of file

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll
new file mode 100644
index 000000000000..c5f2bc9ba5bc
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+sse2 | FileCheck %s 
--check-prefixes=A,B
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 
--allow-unused-prefixes=true --check-prefixes=C,A,UNUSED
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+; A: declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+
+define <2 x i64> @fold_v2i64() {
+entry:
+  %r = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> <i64 255, i64 -1>)
+  ret <2 x i64> %r
+}

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll
new file mode 100644
index 000000000000..bc1990462d37
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+sse2 | FileCheck %s 
--check-prefixes=A,B
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 
--check-prefixes=C,A
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+; A: declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+
+define <2 x i64> @fold_v2i64() {
+entry:
+  %r = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> <i64 255, i64 -1>)
+  ret <2 x i64> %r
+}

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-3.ll 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-3.ll
new file mode 100644
index 000000000000..b478b0ad7215
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-3.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+sse2 | FileCheck %s 
--check-prefixes=A,B
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 
--check-prefixes=A,C
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+; A: declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+
+define <2 x i64> @fold_v2i64() {
+entry:
+  %r = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> <i64 255, i64 -1>)
+  ret <2 x i64> %r
+}

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/prefix-never-matches.ll
 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/prefix-never-matches.ll
new file mode 100644
index 000000000000..fe50a821e4b8
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/prefix-never-matches.ll
@@ -0,0 +1,10 @@
+; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+sse2 | FileCheck %s 
--check-prefixes=A
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 
--check-prefixes=A
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+
+define <2 x i64> @fold_v2i64() {
+entry:
+  %r = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> <i64 255, i64 -1>)
+  ret <2 x i64> %r
+}

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/common-label-
diff erent-bodies.test 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/common-label-
diff erent-bodies.test
new file mode 100644
index 000000000000..409114db02b3
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/common-label-
diff erent-bodies.test
@@ -0,0 +1,14 @@
+# REQUIRES: x86-registered-target
+
+# RUN: cp -f %S/Inputs/common-label-
diff erent-bodies-1.ll %t-1.ll
+# RUN: cp -f %S/Inputs/common-label-
diff erent-bodies-2.ll %t-2.ll
+# RUN: cp -f %S/Inputs/common-label-
diff erent-bodies-3.ll %t-3.ll
+# RUN: %update_llc_test_checks %t-1.ll
+# RUN: %update_llc_test_checks %t-2.ll
+# RUN: %update_llc_test_checks %t-3.ll
+# RUN: FileCheck --input-file=%t-1.ll %s
+# RUN: FileCheck --input-file=%t-2.ll %s
+# RUN: FileCheck --input-file=%t-3.ll %s
+
+# CHECK: B-LABEL: fold_v2i64
+# CHECK-NOT: A-LABEL: fold_v2i64
\ No newline at end of file

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/prefix-never-matches.test
 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/prefix-never-matches.test
new file mode 100644
index 000000000000..c8b15cd39ff3
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/prefix-never-matches.test
@@ -0,0 +1,8 @@
+# REQUIRES: x86-registered-target
+
+# RUN: cp -f %S/Inputs/prefix-never-matches.ll %t.ll
+# RUN: %update_llc_test_checks %t.ll 2>&1 | FileCheck %s
+# RUN: FileCheck --input-file=%t.ll %s --check-prefix=OUTPUT
+
+# CHECK: WARNING: Prefix A had conflicting output
+# OUTPUT-NOT: A:
\ No newline at end of file

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll
 
b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll
new file mode 100644
index 000000000000..972ec5380980
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll
@@ -0,0 +1,7 @@
+; RUN: opt -O0 -S < %s  | FileCheck %s -check-prefix=A
+; RUN: opt -O3 -S < %s  | FileCheck %s -check-prefix=A
+
+define i32 @foo(i32 %i) {
+    %r = add i32 1, 1
+    ret i32 %r
+}
\ No newline at end of file

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test 
b/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
new file mode 100644
index 000000000000..d6d1634a9024
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
@@ -0,0 +1,6 @@
+# RUN: cp -f %S/Inputs/prefix-never-matches.ll %t.ll
+# RUN: %update_test_checks %t.ll 2>&1 | FileCheck %s
+# RUN: FileCheck --input-file=%t.ll %s --check-prefix=OUTPUT
+
+# CHECK: WARNING: Prefix A had conflicting output
+# OUTPUT-NOT: A:
\ No newline at end of file

diff  --git a/llvm/utils/UpdateTestChecks/common.py 
b/llvm/utils/UpdateTestChecks/common.py
index 74c923888d02..8cd90deefdb9 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -258,6 +258,20 @@ def repl_arg_names(match):
   def __str__(self):
     return self.scrub
 
+def get_failed_prefixes(func_dict):
+  # This returns the list of those prefixes that failed to match any function,
+  # because there were conflicting bodies produced by 
diff erent RUN lines, in
+  # all instances of the prefix. Effectivelly, this prefix is unused and should
+  # be removed.
+  for prefix in func_dict:
+    if (not [fct for fct in func_dict[prefix] 
+         if func_dict[prefix][fct] is not None]):
+      yield prefix
+
+def warn_on_failed_prefixes(func_dict):
+  for prefix in get_failed_prefixes(func_dict):
+      warn('Prefix %s had conflicting output from 
diff erent RUN lines for all functions' % (prefix,))
+
 def build_function_body_dictionary(function_re, scrubber, scrubber_args, 
raw_tool_output, prefixes, func_dict, func_order, verbose, record_args, 
check_attributes):
   for m in function_re.finditer(raw_tool_output):
     if not m:
@@ -287,20 +301,28 @@ def build_function_body_dictionary(function_re, scrubber, 
scrubber_args, raw_too
         print('  ' + l, file=sys.stderr)
     for prefix in prefixes:
       if func in func_dict[prefix]:
-        if str(func_dict[prefix][func]) != scrubbed_body or 
(func_dict[prefix][func] and (func_dict[prefix][func].args_and_sig != 
args_and_sig or func_dict[prefix][func].attrs != attrs)):
-          if func_dict[prefix][func] and 
func_dict[prefix][func].is_same_except_arg_names(scrubbed_extra, args_and_sig, 
attrs):
+        if (func_dict[prefix][func] is None or
+            str(func_dict[prefix][func]) != scrubbed_body or
+            func_dict[prefix][func].args_and_sig != args_and_sig or
+                func_dict[prefix][func].attrs != attrs):
+          if (func_dict[prefix][func] is not None and
+              func_dict[prefix][func].is_same_except_arg_names(scrubbed_extra,
+                                                               args_and_sig,
+                                                               attrs)):
             func_dict[prefix][func].scrub = scrubbed_extra
             func_dict[prefix][func].args_and_sig = args_and_sig
             continue
           else:
-            if prefix == prefixes[-1]:
-              warn('Found conflicting asm under the same prefix: %r!' % 
(prefix,))
-            else:
-              func_dict[prefix][func] = None
-              continue
+            # This means a previous RUN line produced a body for this function
+            # that is 
diff erent from the one produced by this current RUN line,
+            # so the body can't be common accross RUN lines. We use None to
+            # indicate that.
+            func_dict[prefix][func] = None
+            continue
 
       func_dict[prefix][func] = function_body(scrubbed_body, scrubbed_extra, 
args_and_sig, attrs)
       func_order[prefix].append(func)
+  warn_on_failed_prefixes(func_dict)
 
 ##### Generator of LLVM IR CHECK lines
 

diff  --git a/llvm/utils/update_test_prefix.py 
b/llvm/utils/update_test_prefix.py
index 28122cc34c40..4e9e18882c69 100755
--- a/llvm/utils/update_test_prefix.py
+++ b/llvm/utils/update_test_prefix.py
@@ -31,7 +31,7 @@ def remove_prefix(i, d=0):
         t = re.search('Assertions have been autogenerated by (.*)', s)
         if t:
             s = os.popen('llvm/' + t.group(1) + ' ' + i + ' 2>&1').read()
-            if 'Found conflicting' in s:
+            if 'had conflicting output from 
diff erent RUN lines for all functions' in s:
                 return -1
             s = os.popen('git 
diff  ' + i).read()
             if re.search('\n(?:-+)\n', s) or re.search('\n[+-].*(?<!RUN):', s):


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to