Index: clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.v2.expected =================================================================== --- /dev/null +++ clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.v2.expected @@ -0,0 +1,43 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2 +// Example input for update_cc_test_checks +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: define dso_local i64 @test +// CHECK-SAME: (i64 noundef [[A:%.*]], i32 noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: [[A_ADDR:%.*]] = alloca i64, align 8 +// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i64 [[A]], ptr [[A_ADDR]], align 8 +// CHECK-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 4 +// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[A_ADDR]], align 8 +// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[B_ADDR]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64 +// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]] +// CHECK-NEXT: ret i64 [[ADD]] +// +long test(long a, int b) { + return a + b; +} + +// A function with a mangled name +// CHECK-LABEL: define dso_local i64 @_Z4testlii +// CHECK-SAME: (i64 noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: [[A_ADDR:%.*]] = alloca i64, align 8 +// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i64 [[A]], ptr [[A_ADDR]], align 8 +// CHECK-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 4 +// CHECK-NEXT: store i32 [[C]], ptr [[C_ADDR]], align 4 +// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[A_ADDR]], align 8 +// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[B_ADDR]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64 +// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]] +// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[C_ADDR]], align 4 +// CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[TMP2]] to i64 +// CHECK-NEXT: [[ADD2:%.*]] = add nsw i64 [[ADD]], [[CONV1]] +// CHECK-NEXT: ret i64 [[ADD2]] +// +__attribute__((overloadable)) long test(long a, int b, int c) { + return a + b + c; +} Index: clang/test/utils/update_cc_test_checks/mangled_names.test =================================================================== --- clang/test/utils/update_cc_test_checks/mangled_names.test +++ clang/test/utils/update_cc_test_checks/mangled_names.test @@ -19,3 +19,8 @@ ## Also try --version 2 # RUN: %update_cc_test_checks %t.c --function-signature --version 2 # RUN: diff -u %t.c %S/Inputs/mangled_names.c.funcsig.v2.expected +## Restore the original file without --function-signature and check that +## --version 2 will implicitly enable it. +# RUN: cp -f %S/Inputs/mangled_names.c %t.c +# RUN: %update_cc_test_checks %t.c --version 2 +# RUN: diff -u %t.c %S/Inputs/mangled_names.c.v2.expected Index: llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.v2.expected =================================================================== --- /dev/null +++ llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.v2.expected @@ -0,0 +1,65 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 +; Example input for update_test_checks (taken from test/Transforms/InstSimplify/add.ll) +; RUN: opt < %s -passes=instsimplify -S | FileCheck %s + +define i32 @common_sub_operand(i32 %X, i32 %Y) { +; CHECK-LABEL: define i32 @common_sub_operand +; CHECK-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]]) { +; CHECK-NEXT: ret i32 [[X]] +; + %Z = sub i32 %X, %Y + %Q = add i32 %Z, %Y + ret i32 %Q +} + +define i32 @negated_operand(i32 %x) { +; CHECK-LABEL: define i32 @negated_operand +; CHECK-SAME: (i32 [[X:%.*]]) { +; CHECK-NEXT: ret i32 0 +; + %negx = sub i32 0, %x + %r = add i32 %negx, %x + ret i32 %r +} + +define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) { +; CHECK-LABEL: define <2 x i32> @negated_operand_commute_vec +; CHECK-SAME: (<2 x i32> [[X:%.*]]) { +; CHECK-NEXT: ret <2 x i32> zeroinitializer +; + %negx = sub <2 x i32> zeroinitializer, %x + %r = add <2 x i32> %x, %negx + ret <2 x i32> %r +} + +define i8 @knownnegation(i8 %x, i8 %y) { +; CHECK-LABEL: define i8 @knownnegation +; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) { +; CHECK-NEXT: ret i8 0 +; + %xy = sub i8 %x, %y + %yx = sub i8 %y, %x + %r = add i8 %xy, %yx + ret i8 %r +} + +define <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) { +; CHECK-LABEL: define <2 x i8> @knownnegation_commute_vec +; CHECK-SAME: (<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) { +; CHECK-NEXT: ret <2 x i8> zeroinitializer +; + %xy = sub <2 x i8> %x, %y + %yx = sub <2 x i8> %y, %x + %r = add <2 x i8> %yx, %xy + ret <2 x i8> %r +} + +define i32 @nameless_value(i32 %X) { +; CHECK-LABEL: define i32 @nameless_value +; CHECK-SAME: (i32 [[X:%.*]]) { +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 42, [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] +; + %1 = sub i32 42, %X + ret i32 %1 +} Index: llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test =================================================================== --- llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test +++ llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test @@ -14,3 +14,8 @@ ## added to the update invocation below. # RUN: %update_test_checks %t.ll # RUN: diff -u %t.ll %S/Inputs/basic.ll.funcsig.expected +## Restore the original file without --function-signature and check that +## --version 2 will implicitly enable it and also check the return type. +# RUN: cp -f %S/Inputs/basic.ll %t.ll +# RUN: %update_test_checks %t.ll --version 2 +# RUN: diff -u %t.ll %S/Inputs/basic.ll.v2.expected Index: llvm/utils/UpdateTestChecks/common.py =================================================================== --- llvm/utils/UpdateTestChecks/common.py +++ llvm/utils/UpdateTestChecks/common.py @@ -22,9 +22,10 @@ Version changelog: 1: Initial version, used by tests that don't specify --version explicitly. -2: --function-signature now also checks return type/attributes. +2: --function-signature is now enabled by default and also checks return + type/attributes. """ -DEFAULT_VERSION = 1 +DEFAULT_VERSION = 2 class Regex(object): """Wrap a compiled regular expression object to allow deep copy of a regexp. @@ -157,6 +158,8 @@ _global_hex_value_regex = args.global_hex_value_regex return args +def check_func_sig(args): + return args.function_signature or args.version > 1 class InputLineInfo(object): def __init__(self, line, line_number, args, argv): @@ -503,9 +506,9 @@ return self.scrub class FunctionTestBuilder: - def __init__(self, run_list, flags, scrubber_args, path): + def __init__(self, run_list, flags, scrubber_args, path, record_args): self._verbose = flags.verbose - self._record_args = flags.function_signature + self._record_args = record_args self._check_attributes = flags.check_attributes # Strip double-quotes if input was read by UTC_ARGS self._filters = list(map(lambda f: Filter(re.compile(f.pattern().strip('"'), Index: llvm/utils/update_analyze_test_checks.py =================================================================== --- llvm/utils/update_analyze_test_checks.py +++ llvm/utils/update_analyze_test_checks.py @@ -98,7 +98,8 @@ 'check_attributes': False, 'replace_value_regex': []}), scrubber_args = [], - path=ti.path) + path=ti.path, + record_args=False) for prefixes, opt_args in prefix_list: common.debug('Extracted opt cmd:', opt_basename, opt_args, file=sys.stderr) Index: llvm/utils/update_cc_test_checks.py =================================================================== --- llvm/utils/update_cc_test_checks.py +++ llvm/utils/update_cc_test_checks.py @@ -298,7 +298,8 @@ run_list=filecheck_run_list, flags=ti.args, scrubber_args=[], - path=ti.path) + path=ti.path, + record_args=common.check_func_sig(ti.args)) for prefixes, args, extra_commands, triple_in_cmd in run_list: # Execute non-filechecked runline. @@ -349,7 +350,7 @@ return common.add_ir_checks(my_output_lines, '//', prefixes, func_dict, func, False, - ti.args.function_signature, + common.check_func_sig(ti.args), ti.args.version, global_vars_seen_dict, is_filtered=builder.is_filtered()) @@ -417,7 +418,7 @@ func_dict, mangled, False, - args.function_signature, + common.check_func_sig(args), args.version, global_vars_seen_dict, is_filtered=builder.is_filtered())) Index: llvm/utils/update_llc_test_checks.py =================================================================== --- llvm/utils/update_llc_test_checks.py +++ llvm/utils/update_llc_test_checks.py @@ -115,11 +115,11 @@ flags=type('', (object,), { 'verbose': ti.args.verbose, 'filters': ti.args.filters, - 'function_signature': False, 'check_attributes': False, 'replace_value_regex': []}), scrubber_args=[ti.args], - path=ti.path) + path=ti.path, + record_args=False) for prefixes, llc_tool, llc_args, preprocess_cmd, triple_in_cmd, march_in_cmd in run_list: common.debug('Extracted LLC cmd:', llc_tool, llc_args) Index: llvm/utils/update_test_checks.py =================================================================== --- llvm/utils/update_test_checks.py +++ llvm/utils/update_test_checks.py @@ -117,7 +117,8 @@ run_list=prefix_list, flags=ti.args, scrubber_args=[], - path=ti.path) + path=ti.path, + record_args=common.check_func_sig(ti.args)) tool_binary = ti.args.tool_binary if not tool_binary: @@ -176,7 +177,7 @@ func_dict, func, False, - args.function_signature, + common.check_func_sig(args), args.version, global_vars_seen_dict, is_filtered=builder.is_filtered()))) @@ -203,7 +204,7 @@ func_dict, func_name, args.preserve_names, - args.function_signature, + common.check_func_sig(args), args.version, global_vars_seen_dict, is_filtered=builder.is_filtered()))