mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
198d8baafb
One of several parallel first steps to remove the target type of pointers, replacing them with a single opaque pointer type. This adds an explicit type parameter to the gep instruction so that when the first parameter becomes an opaque pointer type, the type to gep through is still available to the instructions. * This doesn't modify gep operators, only instructions (operators will be handled separately) * Textual IR changes only. Bitcode (including upgrade) and changing the in-memory representation will be in separate changes. * geps of vectors are transformed as: getelementptr <4 x float*> %x, ... ->getelementptr float, <4 x float*> %x, ... Then, once the opaque pointer type is introduced, this will ultimately look like: getelementptr float, <4 x ptr> %x with the unambiguous interpretation that it is a vector of pointers to float. * address spaces remain on the pointer, not the type: getelementptr float addrspace(1)* %x ->getelementptr float, float addrspace(1)* %x Then, eventually: getelementptr float, ptr addrspace(1) %x Importantly, the massive amount of test case churn has been automated by same crappy python code. I had to manually update a few test cases that wouldn't fit the script's model (r228970,r229196,r229197,r229198). The python script just massages stdin and writes the result to stdout, I then wrapped that in a shell script to handle replacing files, then using the usual find+xargs to migrate all the files. update.py: import fileinput import sys import re ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))") normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))") def conv(match, line): if not match: return line line = match.groups()[0] if len(match.groups()[5]) == 0: line += match.groups()[2] line += match.groups()[3] line += ", " line += match.groups()[1] line += "\n" return line for line in sys.stdin: if line.find("getelementptr ") == line.find("getelementptr inbounds"): if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("): line = conv(re.match(ibrep, line), line) elif line.find("getelementptr ") != line.find("getelementptr ("): line = conv(re.match(normrep, line), line) sys.stdout.write(line) apply.sh: for name in "$@" do python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name" rm -f "$name.tmp" done The actual commands: From llvm/src: find test/ -name *.ll | xargs ./apply.sh From llvm/src/tools/clang: find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}" From llvm/src/tools/polly: find test/ -name *.ll | xargs ./apply.sh After that, check-all (with llvm, clang, clang-tools-extra, lld, compiler-rt, and polly all checked out). The extra 'rm' in the apply.sh script is due to a few files in clang's test suite using interesting unicode stuff that my python script was throwing exceptions on. None of those files needed to be migrated, so it seemed sufficient to ignore those cases. Reviewers: rafael, dexonsmith, grosser Differential Revision: http://reviews.llvm.org/D7636 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230786 91177308-0d34-0410-b5e6-96231b3b80d8
146 lines
5.4 KiB
LLVM
146 lines
5.4 KiB
LLVM
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx,-slow-unaligned-mem-32 | FileCheck %s --check-prefix=ALL --check-prefix=FAST32
|
|
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx,+slow-unaligned-mem-32 | FileCheck %s --check-prefix=ALL --check-prefix=SLOW32
|
|
|
|
define <4 x float> @merge_2_floats(float* nocapture %p) nounwind readonly {
|
|
%tmp1 = load float* %p
|
|
%vecins = insertelement <4 x float> undef, float %tmp1, i32 0
|
|
%add.ptr = getelementptr float, float* %p, i32 1
|
|
%tmp5 = load float* %add.ptr
|
|
%vecins7 = insertelement <4 x float> %vecins, float %tmp5, i32 1
|
|
ret <4 x float> %vecins7
|
|
|
|
; ALL-LABEL: merge_2_floats
|
|
; ALL: vmovq
|
|
; ALL-NEXT: retq
|
|
}
|
|
|
|
; Test-case generated due to a crash when trying to treat loading the first
|
|
; two i64s of a <4 x i64> as a load of two i32s.
|
|
define <4 x i64> @merge_2_floats_into_4() {
|
|
%1 = load i64** undef, align 8
|
|
%2 = getelementptr inbounds i64, i64* %1, i64 0
|
|
%3 = load i64* %2
|
|
%4 = insertelement <4 x i64> undef, i64 %3, i32 0
|
|
%5 = load i64** undef, align 8
|
|
%6 = getelementptr inbounds i64, i64* %5, i64 1
|
|
%7 = load i64* %6
|
|
%8 = insertelement <4 x i64> %4, i64 %7, i32 1
|
|
%9 = shufflevector <4 x i64> %8, <4 x i64> undef, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
|
|
ret <4 x i64> %9
|
|
|
|
; ALL-LABEL: merge_2_floats_into_4
|
|
; ALL: vmovups
|
|
; ALL-NEXT: retq
|
|
}
|
|
|
|
define <4 x float> @merge_4_floats(float* %ptr) {
|
|
%a = load float* %ptr, align 8
|
|
%vec = insertelement <4 x float> undef, float %a, i32 0
|
|
%idx1 = getelementptr inbounds float, float* %ptr, i64 1
|
|
%b = load float* %idx1, align 8
|
|
%vec2 = insertelement <4 x float> %vec, float %b, i32 1
|
|
%idx3 = getelementptr inbounds float, float* %ptr, i64 2
|
|
%c = load float* %idx3, align 8
|
|
%vec4 = insertelement <4 x float> %vec2, float %c, i32 2
|
|
%idx5 = getelementptr inbounds float, float* %ptr, i64 3
|
|
%d = load float* %idx5, align 8
|
|
%vec6 = insertelement <4 x float> %vec4, float %d, i32 3
|
|
ret <4 x float> %vec6
|
|
|
|
; ALL-LABEL: merge_4_floats
|
|
; ALL: vmovups
|
|
; ALL-NEXT: retq
|
|
}
|
|
|
|
; PR21710 ( http://llvm.org/bugs/show_bug.cgi?id=21710 )
|
|
; Make sure that 32-byte vectors are handled efficiently.
|
|
; If the target has slow 32-byte accesses, we should still generate
|
|
; 16-byte loads.
|
|
|
|
define <8 x float> @merge_8_floats(float* %ptr) {
|
|
%a = load float* %ptr, align 4
|
|
%vec = insertelement <8 x float> undef, float %a, i32 0
|
|
%idx1 = getelementptr inbounds float, float* %ptr, i64 1
|
|
%b = load float* %idx1, align 4
|
|
%vec2 = insertelement <8 x float> %vec, float %b, i32 1
|
|
%idx3 = getelementptr inbounds float, float* %ptr, i64 2
|
|
%c = load float* %idx3, align 4
|
|
%vec4 = insertelement <8 x float> %vec2, float %c, i32 2
|
|
%idx5 = getelementptr inbounds float, float* %ptr, i64 3
|
|
%d = load float* %idx5, align 4
|
|
%vec6 = insertelement <8 x float> %vec4, float %d, i32 3
|
|
%idx7 = getelementptr inbounds float, float* %ptr, i64 4
|
|
%e = load float* %idx7, align 4
|
|
%vec8 = insertelement <8 x float> %vec6, float %e, i32 4
|
|
%idx9 = getelementptr inbounds float, float* %ptr, i64 5
|
|
%f = load float* %idx9, align 4
|
|
%vec10 = insertelement <8 x float> %vec8, float %f, i32 5
|
|
%idx11 = getelementptr inbounds float, float* %ptr, i64 6
|
|
%g = load float* %idx11, align 4
|
|
%vec12 = insertelement <8 x float> %vec10, float %g, i32 6
|
|
%idx13 = getelementptr inbounds float, float* %ptr, i64 7
|
|
%h = load float* %idx13, align 4
|
|
%vec14 = insertelement <8 x float> %vec12, float %h, i32 7
|
|
ret <8 x float> %vec14
|
|
|
|
; ALL-LABEL: merge_8_floats
|
|
|
|
; FAST32: vmovups
|
|
; FAST32-NEXT: retq
|
|
|
|
; SLOW32: vmovups
|
|
; SLOW32-NEXT: vinsertf128
|
|
; SLOW32-NEXT: retq
|
|
}
|
|
|
|
define <4 x double> @merge_4_doubles(double* %ptr) {
|
|
%a = load double* %ptr, align 8
|
|
%vec = insertelement <4 x double> undef, double %a, i32 0
|
|
%idx1 = getelementptr inbounds double, double* %ptr, i64 1
|
|
%b = load double* %idx1, align 8
|
|
%vec2 = insertelement <4 x double> %vec, double %b, i32 1
|
|
%idx3 = getelementptr inbounds double, double* %ptr, i64 2
|
|
%c = load double* %idx3, align 8
|
|
%vec4 = insertelement <4 x double> %vec2, double %c, i32 2
|
|
%idx5 = getelementptr inbounds double, double* %ptr, i64 3
|
|
%d = load double* %idx5, align 8
|
|
%vec6 = insertelement <4 x double> %vec4, double %d, i32 3
|
|
ret <4 x double> %vec6
|
|
|
|
; ALL-LABEL: merge_4_doubles
|
|
; FAST32: vmovups
|
|
; FAST32-NEXT: retq
|
|
|
|
; SLOW32: vmovups
|
|
; SLOW32-NEXT: vinsertf128
|
|
; SLOW32-NEXT: retq
|
|
}
|
|
|
|
; PR21771 ( http://llvm.org/bugs/show_bug.cgi?id=21771 )
|
|
; Recognize and combine consecutive loads even when the
|
|
; first of the combined loads is offset from the base address.
|
|
define <4 x double> @merge_4_doubles_offset(double* %ptr) {
|
|
%arrayidx4 = getelementptr inbounds double, double* %ptr, i64 4
|
|
%arrayidx5 = getelementptr inbounds double, double* %ptr, i64 5
|
|
%arrayidx6 = getelementptr inbounds double, double* %ptr, i64 6
|
|
%arrayidx7 = getelementptr inbounds double, double* %ptr, i64 7
|
|
%e = load double* %arrayidx4, align 8
|
|
%f = load double* %arrayidx5, align 8
|
|
%g = load double* %arrayidx6, align 8
|
|
%h = load double* %arrayidx7, align 8
|
|
%vecinit4 = insertelement <4 x double> undef, double %e, i32 0
|
|
%vecinit5 = insertelement <4 x double> %vecinit4, double %f, i32 1
|
|
%vecinit6 = insertelement <4 x double> %vecinit5, double %g, i32 2
|
|
%vecinit7 = insertelement <4 x double> %vecinit6, double %h, i32 3
|
|
ret <4 x double> %vecinit7
|
|
|
|
; ALL-LABEL: merge_4_doubles_offset
|
|
; FAST32: vmovups
|
|
; FAST32-NEXT: retq
|
|
|
|
; SLOW32: vmovups
|
|
; SLOW32-NEXT: vinsertf128
|
|
; SLOW32-NEXT: retq
|
|
}
|
|
|