diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s @@ -0,0 +1,38 @@ + .text + .section .AMDGPU.config + .long 47176 + .long 0 + .long 47180 + .long 0 + .long 47200 + .long 0 + .long 4 + .long 0 + .long 8 + .long 0 + .text + .hidden main ; -- Begin function main + .globl main + .p2align 2 + .type main,@function +main: ; @main +; %bb.0: + s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) + v_add_u32_e64 v1, v0, v0 + ; implicit-def: $sgpr4 + ; implicit-def: $sgpr4 + v_mul_lo_u32 v0, v1, v0 + v_sub_u32_e64 v0, v0, v1 + s_setpc_b64 s[30:31] +.Lfunc_end0: + .size main, .Lfunc_end0-main + ; -- End function + .section .AMDGPU.csdata +; Function info: +; codeLenInByte = 32 +; NumSgprs: 36 +; NumVgprs: 2 +; ScratchSize: 0 +; MemoryBound: 0 + .section ".note.GNU-stack" + .amd_amdgpu_isa "amdgcn-unknown---gfx900" diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s @@ -0,0 +1,36 @@ + .text + .section .AMDGPU.config + .long 47176 + .long 0 + .long 47180 + .long 0 + .long 47200 + .long 0 + .long 4 + .long 0 + .long 8 + .long 0 + .text + .hidden main ; -- Begin function main + .globl main + .p2align 2 + .type main,@function +main: ; @main +; %bb.0: + s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) + v_add_u32_e32 v1, v0, v0 + v_mul_lo_u32 v0, v1, v0 + v_sub_u32_e32 v0, v0, v1 + s_setpc_b64 s[30:31] +.Lfunc_end0: + .size main, .Lfunc_end0-main + ; -- End function + .section .AMDGPU.csdata +; Function info: +; codeLenInByte = 24 +; NumSgprs: 36 +; NumVgprs: 2 +; ScratchSize: 0 +; MemoryBound: 0 + .section ".note.GNU-stack" + .amd_amdgpu_isa "amdgcn-unknown---gfx900" diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll --- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll @@ -1,5 +1,8 @@ -; RUN: llc -O0 -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O0 %s -; RUN: llc -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O3 %s +; llc is replaced with cat, we just simulate llc by printing text from these files +; RUN: llc %S/amdgpu_no_merge_comments-O0.s | FileCheck -check-prefixes=GCN,GFX9-O0 %s +; RUN: llc %S/amdgpu_no_merge_comments-O3.s | FileCheck -check-prefixes=GCN,GFX9-O3 %s + +target triple = "amdgcn--" define hidden i32 @main(i32 %a) { %add = add i32 %a, %a diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll.expected b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll.expected --- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll.expected +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll.expected @@ -1,6 +1,9 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py -; RUN: llc -O0 -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O0 %s -; RUN: llc -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O3 %s +; llc is replaced with cat, we just simulate llc by printing text from these files +; RUN: llc %S/amdgpu_no_merge_comments-O0.s | FileCheck -check-prefixes=GCN,GFX9-O0 %s +; RUN: llc %S/amdgpu_no_merge_comments-O3.s | FileCheck -check-prefixes=GCN,GFX9-O3 %s + +target triple = "amdgcn--" define hidden i32 @main(i32 %a) { ; GFX9-O0-LABEL: main: diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test --- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test @@ -1,5 +1,8 @@ # REQUIRES: amdgpu-registered-target ## Check that functions with different IR comments in the output are not merged -# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments.ll %t.ll && %update_llc_test_checks %t.ll +# Replace llc with cat, so we can simulate hypothetical output without actually running llc. +# Copy the simulated output to the temporary directory. +# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments-O0.s %T/ && cp -f %S/Inputs/amdgpu_no_merge_comments-O3.s %T/ +# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments.ll %t.ll && %update_llc_test_checks --llc-binary cat %t.ll # RUN: diff -u %S/Inputs/amdgpu_no_merge_comments.ll.expected %t.ll 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 @@ -147,16 +147,31 @@ return True +# Perform lit-like substitutions +def getSubstitutions(sourcepath): + sourcedir = os.path.dirname(sourcepath) + return [('%s', sourcepath), + ('%S', sourcedir), + ('%p', sourcedir), + ('%{pathsep}', os.pathsep)] + +def applySubstitutions(s, substitutions): + for a,b in substitutions: + s = s.replace(a, b) + return s + # Invoke the tool that is being tested. def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): with open(ir) as ir_file: + substitutions = getSubstitutions(ir) + # TODO Remove the str form which is used by update_test_checks.py and # update_llc_test_checks.py # The safer list form is used by update_cc_test_checks.py if preprocess_cmd: # Allow pre-processing the IR file (e.g. using sed): assert isinstance(preprocess_cmd, str) # TODO: use a list instead of using shell - preprocess_cmd = preprocess_cmd.replace('%s', ir).strip() + preprocess_cmd = applySubstitutions(preprocess_cmd, substitutions).strip() if verbose: print('Pre-processing input file: ', ir, " with command '", preprocess_cmd, "'", sep="", file=sys.stderr) @@ -165,10 +180,12 @@ pp = subprocess.Popen(preprocess_cmd, shell=True, stdin=devnull, stdout=subprocess.PIPE) ir_file = pp.stdout + if isinstance(cmd_args, list): - stdout = subprocess.check_output([exe] + cmd_args, stdin=ir_file) + args = [applySubstitutions(a, substitutions) for a in cmd_args] + stdout = subprocess.check_output([exe] + args, stdin=ir_file) else: - stdout = subprocess.check_output(exe + ' ' + cmd_args, + stdout = subprocess.check_output(exe + ' ' + applySubstitutions(cmd_args, substitutions), shell=True, stdin=ir_file) if sys.version_info[0] > 2: stdout = stdout.decode()