diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll @@ -0,0 +1,59 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes +; Example input for update_test_checks (taken from test/Transforms/InstSimplify/add.ll) +; RUN: opt < %s -instsimplify -S | FileCheck %s + +define i32 @common_sub_operand(i32 %X, i32 %Y) { +; CHECK-LABEL: @common_sub_operand( +; 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: @negated_operand( +; 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: @negated_operand_commute_vec( +; 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: @knownnegation( +; 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: @knownnegation_commute_vec( +; 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: @nameless_value( +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 42, [[X:%.*]] +; CHECK-NEXT: ret i32 [[TMP1]] +; + %1 = sub i32 42, %X + ret i32 %1 +} diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll.expected new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/UTC_ARGS.ll.expected @@ -0,0 +1,65 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes +; Example input for update_test_checks (taken from test/Transforms/InstSimplify/add.ll) +; RUN: opt < %s -instsimplify -S | FileCheck %s + +define i32 @common_sub_operand(i32 %X, i32 %Y) { +; CHECK-LABEL: define {{[^@]+}}@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 {{[^@]+}}@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 {{[^@]+}}@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 {{[^@]+}}@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 {{[^@]+}}@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 {{[^@]+}}@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 +} diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/UTC_ARGS.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/UTC_ARGS.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/UTC_ARGS.test @@ -0,0 +1,7 @@ +# REQUIRES: x86-registered-target +## UTC_ARGS test checking that update_test_checks.py works correctly +# RUN: cp -f %S/Inputs/UTC_ARGS.ll %t.ll && %update_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/UTC_ARGS.ll.expected +## Check that running the script again does not change the result: +# RUN: %update_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/UTC_ARGS.ll.expected diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -588,8 +588,9 @@ def check_for_command(line, parser, args, argv, argparse_callback): cmd_m = UTC_ARGS_CMD.match(line) if cmd_m: - cmd = cmd_m.group('cmd').strip().split(' ') - argv = argv + cmd + for option in cmd_m.group('cmd').strip().split(' '): + if option: + argv.append(option) args = parser.parse_args(filter(lambda arg: arg not in args.tests, argv)) if argparse_callback is not None: argparse_callback(args)