2012-08-21 16:39:44 +08:00
; RUN: opt < %s -instcombine -S | FileCheck %s
2009-11-03 23:29:06 +08:00
target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
2007-04-25 14:29:34 +08:00
@C.0.1248 = internal constant [ 128 x float ] [ float -1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float -1.000000e+00 , float 0.000000e+00 , float 1.000000e+00 , float 1.000000e+00 , float 1.000000e+00 ] , align 32 ; <[128 x float]*> [#uses=1]
2010-11-18 14:16:43 +08:00
define float @test1 ( i32 %hash , float %x , float %y , float %z , float %w ) {
2007-04-25 14:29:34 +08:00
entry:
%lookupTable = alloca [ 128 x float ] , align 16 ; <[128 x float]*> [#uses=5]
%lookupTable1 = bitcast [ 128 x float ] * %lookupTable to i8 * ; <i8*> [#uses=1]
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %lookupTable1 , i8 * bitcast ( [ 128 x float ] * @C.0.1248 to i8 * ) , i64 512 , i32 16 , i1 false )
2014-04-24 08:01:09 +08:00
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test1(
2010-11-18 14:16:43 +08:00
; CHECK-NOT: alloca
; CHECK-NOT: call{{.*}}@llvm.memcpy
2014-04-24 08:01:09 +08:00
2007-04-25 14:29:34 +08:00
%tmp3 = shl i32 %hash , 2 ; <i32> [#uses=1]
%tmp5 = and i32 %tmp3 , 124 ; <i32> [#uses=4]
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
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
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
%tmp753 = getelementptr [ 128 x float ] , [ 128 x float ] * %lookupTable , i32 0 , i32 %tmp5 ; <float*> [#uses=1]
2015-02-28 05:17:42 +08:00
%tmp9 = load float , float * %tmp753 ; <float> [#uses=1]
2009-06-05 06:49:04 +08:00
%tmp11 = fmul float %tmp9 , %x ; <float> [#uses=1]
%tmp13 = fadd float %tmp11 , 0.000000e+00 ; <float> [#uses=1]
2007-04-25 14:29:34 +08:00
%tmp17.sum52 = or i32 %tmp5 , 1 ; <i32> [#uses=1]
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
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
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
%tmp1851 = getelementptr [ 128 x float ] , [ 128 x float ] * %lookupTable , i32 0 , i32 %tmp17.sum52 ; <float*> [#uses=1]
2015-02-28 05:17:42 +08:00
%tmp19 = load float , float * %tmp1851 ; <float> [#uses=1]
2009-06-05 06:49:04 +08:00
%tmp21 = fmul float %tmp19 , %y ; <float> [#uses=1]
%tmp23 = fadd float %tmp21 , %tmp13 ; <float> [#uses=1]
2007-04-25 14:29:34 +08:00
%tmp27.sum50 = or i32 %tmp5 , 2 ; <i32> [#uses=1]
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
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
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
%tmp2849 = getelementptr [ 128 x float ] , [ 128 x float ] * %lookupTable , i32 0 , i32 %tmp27.sum50 ; <float*> [#uses=1]
2015-02-28 05:17:42 +08:00
%tmp29 = load float , float * %tmp2849 ; <float> [#uses=1]
2009-06-05 06:49:04 +08:00
%tmp31 = fmul float %tmp29 , %z ; <float> [#uses=1]
%tmp33 = fadd float %tmp31 , %tmp23 ; <float> [#uses=1]
2007-04-25 14:29:34 +08:00
%tmp37.sum48 = or i32 %tmp5 , 3 ; <i32> [#uses=1]
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
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
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
%tmp3847 = getelementptr [ 128 x float ] , [ 128 x float ] * %lookupTable , i32 0 , i32 %tmp37.sum48 ; <float*> [#uses=1]
2015-02-28 05:17:42 +08:00
%tmp39 = load float , float * %tmp3847 ; <float> [#uses=1]
2009-06-05 06:49:04 +08:00
%tmp41 = fmul float %tmp39 , %w ; <float> [#uses=1]
%tmp43 = fadd float %tmp41 , %tmp33 ; <float> [#uses=1]
2007-04-25 14:29:34 +08:00
ret float %tmp43
}
2015-11-19 13:56:52 +08:00
declare void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * nocapture , i8 * nocapture , i64 , i32 , i1 ) nounwind
declare void @llvm.memcpy.p1i8.p0i8.i64 ( i8 addrspace ( 1 ) * nocapture , i8 * nocapture , i64 , i32 , i1 ) nounwind
declare void @llvm.memcpy.p0i8.p1i8.i64 ( i8 * nocapture , i8 addrspace ( 1 ) * nocapture , i64 , i32 , i1 ) nounwind
declare void @llvm.memcpy.p1i8.p1i8.i64 ( i8 addrspace ( 1 ) * nocapture , i8 addrspace ( 1 ) * nocapture , i64 , i32 , i1 ) nounwind
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
%T = type { i8 , [ 123 x i8 ] }
2012-05-20 06:52:10 +08:00
%U = type { i32 , i32 , i32 , i32 , i32 }
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
@G = constant %T { i8 1 , [ 123 x i8 ] zeroinitializer }
2012-05-20 06:52:10 +08:00
@H = constant [ 2 x %U ] zeroinitializer , align 16
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
define void @test2 ( ) {
%A = alloca %T
%B = alloca %T
%a = bitcast %T * %A to i8 *
%b = bitcast %T * %B to i8 *
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test2(
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
; %A alloca is deleted
2012-08-21 16:39:44 +08:00
; CHECK-NEXT: alloca [124 x i8]
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
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
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
; CHECK-NEXT: getelementptr inbounds [124 x i8], [124 x i8]*
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
; use @G instead of %A
2015-11-19 13:56:52 +08:00
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0)
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %T * @G to i8 * ) , i64 124 , i32 4 , i1 false )
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %b , i8 * %a , i64 124 , i32 4 , i1 false )
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
call void @bar ( i8 * %b )
ret void
}
2014-04-24 08:01:09 +08:00
define void @test2_addrspacecast ( ) {
%A = alloca %T
%B = alloca %T
%a = addrspacecast %T * %A to i8 addrspace ( 1 ) *
%b = addrspacecast %T * %B to i8 addrspace ( 1 ) *
; CHECK-LABEL: @test2_addrspacecast(
; %A alloca is deleted
; This doesn't exactly match what test2 does, because folding the type
; cast into the alloca doesn't work for the addrspacecast yet.
2014-06-07 05:52:55 +08:00
; CHECK-NEXT: alloca [124 x i8]
; CHECK-NEXT: getelementptr
2014-04-24 08:01:09 +08:00
; CHECK-NEXT: addrspacecast
; use @G instead of %A
2015-11-19 13:56:52 +08:00
; CHECK-NEXT: call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %{{.*}},
call void @llvm.memcpy.p1i8.p0i8.i64 ( i8 addrspace ( 1 ) * %a , i8 * bitcast ( %T * @G to i8 * ) , i64 124 , i32 4 , i1 false )
call void @llvm.memcpy.p1i8.p1i8.i64 ( i8 addrspace ( 1 ) * %b , i8 addrspace ( 1 ) * %a , i64 124 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @bar_as1 ( i8 addrspace ( 1 ) * %b )
ret void
}
fix a small oversight in the "eliminate memcpy from constant global"
optimization. If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load. We now optimize the testcase to:
define void @test2() {
%B = alloca %T
%a = bitcast %T* @G to i8*
%b = bitcast %T* %B to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
call void @bar(i8* %b)
ret void
}
previously we would generate:
define void @test() {
%B = alloca %T
%b = bitcast %T* %B to i8*
%G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
%tmp3 = load i8* %G.0, align 4
%G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
%G.15 = bitcast [123 x i8]* %G.1 to i8*
%1 = bitcast [123 x i8]* %G.1 to i984*
%srcval = load i984* %1, align 1
%B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
store i8 %tmp3, i8* %B.0, align 4
%B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
%B.12 = bitcast [123 x i8]* %B.1 to i8*
%2 = bitcast [123 x i8]* %B.1 to i984*
store i984 %srcval, i984* %2, align 1
call void @bar(i8* %b)
ret void
}
llvm-svn: 119682
2010-11-18 14:20:47 +08:00
declare void @bar ( i8 * )
2014-04-24 08:01:09 +08:00
declare void @bar_as1 ( i8 addrspace ( 1 ) * )
2010-11-18 14:26:49 +08:00
;; Should be able to eliminate the alloca.
define void @test3 ( ) {
%A = alloca %T
%a = bitcast %T * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %T * @G to i8 * ) , i64 124 , i32 4 , i1 false )
2010-11-18 14:26:49 +08:00
call void @bar ( i8 * %a ) readonly
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test3(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @bar(i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0))
2010-11-18 14:26:49 +08:00
ret void
}
2010-11-18 14:41:51 +08:00
2014-04-24 08:01:09 +08:00
define void @test3_addrspacecast ( ) {
%A = alloca %T
%a = bitcast %T * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p1i8.i64 ( i8 * %a , i8 addrspace ( 1 ) * addrspacecast ( %T * @G to i8 addrspace ( 1 ) * ) , i64 124 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @bar ( i8 * %a ) readonly
; CHECK-LABEL: @test3_addrspacecast(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @bar(i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0))
2014-04-24 08:01:09 +08:00
ret void
}
2010-11-18 14:41:51 +08:00
define void @test4 ( ) {
%A = alloca %T
%a = bitcast %T * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %T * @G to i8 * ) , i64 124 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @baz ( i8 * byval %a )
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test4(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T, %T* @G, i64 0, i32 0))
2010-11-18 14:41:51 +08:00
ret void
}
2011-06-27 13:40:02 +08:00
declare void @llvm.lifetime.start ( i64 , i8 * )
define void @test5 ( ) {
%A = alloca %T
%a = bitcast %T * %A to i8 *
call void @llvm.lifetime.start ( i64 -1 , i8 * %a )
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %T * @G to i8 * ) , i64 124 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @baz ( i8 * byval %a )
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test5(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T, %T* @G, i64 0, i32 0))
2011-06-27 13:40:02 +08:00
ret void
}
2010-11-18 14:41:51 +08:00
declare void @baz ( i8 * byval )
2012-05-20 06:52:10 +08:00
define void @test6 ( ) {
%A = alloca %U , align 16
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( [ 2 x %U ] * @H to i8 * ) , i64 20 , i32 16 , i1 false )
2012-05-20 06:52:10 +08:00
call void @bar ( i8 * %a ) readonly
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test6(
2012-08-21 16:39:44 +08:00
; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*))
2012-05-20 06:52:10 +08:00
ret void
}
define void @test7 ( ) {
%A = alloca %U , align 16
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %U * getelementptr ( [ 2 x %U ] , [ 2 x %U ] * @H , i64 0 , i32 0 ) to i8 * ) , i64 20 , i32 4 , i1 false )
2012-05-20 06:52:10 +08:00
call void @bar ( i8 * %a ) readonly
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test7(
2012-08-21 16:39:44 +08:00
; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*))
2012-05-20 06:52:10 +08:00
ret void
}
define void @test8 ( ) {
%A = alloca %U , align 16
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %U * getelementptr ( [ 2 x %U ] , [ 2 x %U ] * @H , i64 0 , i32 1 ) to i8 * ) , i64 20 , i32 4 , i1 false )
2012-05-20 06:52:10 +08:00
call void @bar ( i8 * %a ) readonly
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test8(
2012-05-20 06:52:10 +08:00
; CHECK: llvm.memcpy
; CHECK: bar
ret void
}
2012-11-27 07:04:53 +08:00
2014-04-24 08:01:09 +08:00
define void @test8_addrspacecast ( ) {
%A = alloca %U , align 16
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p1i8.i64 ( i8 * %a , i8 addrspace ( 1 ) * addrspacecast ( %U * getelementptr ( [ 2 x %U ] , [ 2 x %U ] * @H , i64 0 , i32 1 ) to i8 addrspace ( 1 ) * ) , i64 20 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @bar ( i8 * %a ) readonly
; CHECK-LABEL: @test8_addrspacecast(
; CHECK: llvm.memcpy
; CHECK: bar
ret void
}
2012-11-27 07:04:53 +08:00
define void @test9 ( ) {
%A = alloca %U , align 4
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p0i8.i64 ( i8 * %a , i8 * bitcast ( %U * getelementptr ( [ 2 x %U ] , [ 2 x %U ] * @H , i64 0 , i32 1 ) to i8 * ) , i64 20 , i32 4 , i1 false )
2012-11-27 07:04:53 +08:00
call void @bar ( i8 * %a ) readonly
2013-07-14 09:42:54 +08:00
; CHECK-LABEL: @test9(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @bar(i8* bitcast (%U* getelementptr inbounds ([2 x %U], [2 x %U]* @H, i64 0, i64 1) to i8*))
2012-11-27 07:04:53 +08:00
ret void
}
2014-04-24 08:01:09 +08:00
define void @test9_addrspacecast ( ) {
%A = alloca %U , align 4
%a = bitcast %U * %A to i8 *
2015-11-19 13:56:52 +08:00
call void @llvm.memcpy.p0i8.p1i8.i64 ( i8 * %a , i8 addrspace ( 1 ) * addrspacecast ( %U * getelementptr ( [ 2 x %U ] , [ 2 x %U ] * @H , i64 0 , i32 1 ) to i8 addrspace ( 1 ) * ) , i64 20 , i32 4 , i1 false )
2014-04-24 08:01:09 +08:00
call void @bar ( i8 * %a ) readonly
; CHECK-LABEL: @test9_addrspacecast(
2015-03-14 02:20:45 +08:00
; CHECK-NEXT: call void @bar(i8* bitcast (%U* getelementptr inbounds ([2 x %U], [2 x %U]* @H, i64 0, i64 1) to i8*))
2014-04-24 08:01:09 +08:00
ret void
}