2014-07-15 08:07:27 +08:00
|
|
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
2015-01-24 12:19:17 +08:00
|
|
|
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
|
2014-07-15 08:07:27 +08:00
|
|
|
|
2003-06-26 13:05:51 +08:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
2014-07-15 08:07:27 +08:00
|
|
|
|
2015-01-22 13:08:12 +08:00
|
|
|
target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
2003-06-26 13:05:51 +08:00
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
@X = constant i32 42 ; <i32*> [#uses=2]
|
|
|
|
@X2 = constant i32 47 ; <i32*> [#uses=1]
|
|
|
|
@Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
|
|
|
|
@Z = constant [2 x { i32, float }] zeroinitializer ; <[2 x { i32, float }]*> [#uses=1]
|
2003-06-26 13:05:51 +08:00
|
|
|
|
2010-07-12 08:19:47 +08:00
|
|
|
@GLOBAL = internal constant [4 x i32] zeroinitializer
|
|
|
|
|
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test1() {
|
2015-02-28 05:17:42 +08:00
|
|
|
%B = load i32, i32* @X ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %B
|
2004-05-28 01:43:33 +08:00
|
|
|
}
|
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define float @test2() {
|
[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
|
|
|
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1 ; <float*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%B = load float, float* %A ; <float> [#uses=1]
|
2003-06-26 13:05:51 +08:00
|
|
|
ret float %B
|
|
|
|
}
|
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test3() {
|
[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
|
|
|
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0 ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%B = load i32, i32* %A ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %B
|
2003-06-26 13:05:51 +08:00
|
|
|
}
|
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test4() {
|
[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
|
|
|
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0 ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%B = load i32, i32* %A ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %B
|
2004-05-28 01:28:55 +08:00
|
|
|
}
|
2004-09-20 02:43:01 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test5(i1 %C) {
|
|
|
|
%Y = select i1 %C, i32* @X, i32* @X2 ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%Z = load i32, i32* %Y ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %Z
|
2004-09-20 02:43:01 +08:00
|
|
|
}
|
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test7(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test7(i32 %X) {
|
[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
|
|
|
%V = getelementptr i32, i32* null, i32 %X ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%R = load i32, i32* %V ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %R
|
2005-05-01 12:24:15 +08:00
|
|
|
}
|
2005-09-13 05:59:22 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test8(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test8(i32* %P) {
|
|
|
|
store i32 1, i32* %P
|
2015-02-28 05:17:42 +08:00
|
|
|
%X = load i32, i32* %P ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %X
|
2005-09-13 05:59:22 +08:00
|
|
|
}
|
2005-09-13 06:19:46 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test9(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test9(i32* %P) {
|
2015-02-28 05:17:42 +08:00
|
|
|
%X = load i32, i32* %P ; <i32> [#uses=1]
|
|
|
|
%Y = load i32, i32* %P ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
%Z = sub i32 %X, %Y ; <i32> [#uses=1]
|
|
|
|
ret i32 %Z
|
2005-09-13 06:19:46 +08:00
|
|
|
}
|
2005-09-13 07:22:17 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test10(
|
|
|
|
; CHECK-NOT: load
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
|
|
|
|
br i1 %C.upgrd.1, label %T, label %F
|
|
|
|
T: ; preds = %0
|
|
|
|
store i32 1, i32* %Q
|
|
|
|
store i32 0, i32* %P
|
2005-09-13 07:22:17 +08:00
|
|
|
br label %C
|
2008-03-25 12:26:08 +08:00
|
|
|
F: ; preds = %0
|
|
|
|
store i32 0, i32* %P
|
2005-09-13 07:22:17 +08:00
|
|
|
br label %C
|
2008-03-25 12:26:08 +08:00
|
|
|
C: ; preds = %F, %T
|
2015-02-28 05:17:42 +08:00
|
|
|
%V = load i32, i32* %P ; <i32> [#uses=1]
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32 %V
|
2005-09-13 07:22:17 +08:00
|
|
|
}
|
2008-10-16 07:19:35 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test11(
|
|
|
|
; CHECK-NOT: load
|
2008-10-16 07:19:35 +08:00
|
|
|
define double @test11(double* %p) {
|
[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
|
|
|
%t0 = getelementptr double, double* %p, i32 1
|
2008-10-16 07:19:35 +08:00
|
|
|
store double 2.0, double* %t0
|
[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
|
|
|
%t1 = getelementptr double, double* %p, i32 1
|
2015-02-28 05:17:42 +08:00
|
|
|
%x = load double, double* %t1
|
2008-10-16 07:19:35 +08:00
|
|
|
ret double %x
|
|
|
|
}
|
2010-01-06 05:32:59 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test12(
|
|
|
|
; CHECK-NOT: load
|
2010-01-06 05:32:59 +08:00
|
|
|
define i32 @test12(i32* %P) {
|
2014-07-15 08:07:27 +08:00
|
|
|
%A = alloca i32
|
|
|
|
store i32 123, i32* %A
|
|
|
|
; Cast the result of the load not the source
|
|
|
|
%Q = bitcast i32* %A to i32*
|
2015-02-28 05:17:42 +08:00
|
|
|
%V = load i32, i32* %Q
|
2014-07-15 08:07:27 +08:00
|
|
|
ret i32 %V
|
2010-01-06 05:32:59 +08:00
|
|
|
}
|
2010-07-12 08:19:47 +08:00
|
|
|
|
2014-07-15 08:07:27 +08:00
|
|
|
; CHECK-LABEL: @test13(
|
|
|
|
; CHECK-NOT: load
|
2010-07-12 08:19:47 +08:00
|
|
|
define <16 x i8> @test13(<2 x i64> %x) {
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load <16 x i8>, <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
|
2014-07-15 08:07:27 +08:00
|
|
|
ret <16 x i8> %tmp
|
2010-07-12 08:19:47 +08:00
|
|
|
}
|
2014-10-20 18:03:01 +08:00
|
|
|
|
|
|
|
define i8 @test14(i8 %x, i32 %y) {
|
|
|
|
; This test must not have the store of %x forwarded to the load -- there is an
|
|
|
|
; intervening store if %y. However, the intervening store occurs with a different
|
|
|
|
; type and size and to a different pointer value. This is ensuring that none of
|
|
|
|
; those confuse the analysis into thinking that the second store does not alias
|
|
|
|
; the first.
|
|
|
|
; CHECK-LABEL: @test14(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: %[[R:.*]] = load i8, i8*
|
2014-10-20 18:03:01 +08:00
|
|
|
; CHECK-NEXT: ret i8 %[[R]]
|
|
|
|
%a = alloca i32
|
|
|
|
%a.i8 = bitcast i32* %a to i8*
|
|
|
|
store i8 %x, i8* %a.i8
|
|
|
|
store i32 %y, i32* %a
|
2015-02-28 05:17:42 +08:00
|
|
|
%r = load i8, i8* %a.i8
|
2014-10-20 18:03:01 +08:00
|
|
|
ret i8 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
@test15_global = external global i32
|
|
|
|
|
|
|
|
define i8 @test15(i8 %x, i32 %y) {
|
|
|
|
; Same test as @test14 essentially, but using a global instead of an alloca.
|
|
|
|
; CHECK-LABEL: @test15(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: %[[R:.*]] = load i8, i8*
|
2014-10-20 18:03:01 +08:00
|
|
|
; CHECK-NEXT: ret i8 %[[R]]
|
|
|
|
%g.i8 = bitcast i32* @test15_global to i8*
|
|
|
|
store i8 %x, i8* %g.i8
|
|
|
|
store i32 %y, i32* @test15_global
|
2015-02-28 05:17:42 +08:00
|
|
|
%r = load i8, i8* %g.i8
|
2014-10-20 18:03:01 +08:00
|
|
|
ret i8 %r
|
|
|
|
}
|
2015-01-22 13:08:12 +08:00
|
|
|
|
|
|
|
define void @test16(i8* %x, i8* %a, i8* %b, i8* %c) {
|
|
|
|
; Check that we canonicalize loads which are only stored to use integer types
|
|
|
|
; when there is a valid integer type.
|
|
|
|
; CHECK-LABEL: @test16(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: %[[L1:.*]] = load i32, i32*
|
2015-01-22 13:08:12 +08:00
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: store i32 %[[L1]], i32*
|
|
|
|
; CHECK: store i32 %[[L1]], i32*
|
|
|
|
; CHECK-NOT: store
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: %[[L1:.*]] = load i32, i32*
|
2015-01-22 13:08:12 +08:00
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: store i32 %[[L1]], i32*
|
|
|
|
; CHECK: store i32 %[[L1]], i32*
|
|
|
|
; CHECK-NOT: store
|
|
|
|
; CHECK: ret
|
|
|
|
|
|
|
|
entry:
|
|
|
|
%x.cast = bitcast i8* %x to float*
|
|
|
|
%a.cast = bitcast i8* %a to float*
|
|
|
|
%b.cast = bitcast i8* %b to float*
|
|
|
|
%c.cast = bitcast i8* %c to i32*
|
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load float, float* %x.cast
|
2015-01-22 13:08:12 +08:00
|
|
|
store float %x1, float* %a.cast
|
|
|
|
store float %x1, float* %b.cast
|
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%x2 = load float, float* %x.cast
|
2015-01-22 13:08:12 +08:00
|
|
|
store float %x2, float* %b.cast
|
|
|
|
%x2.cast = bitcast float %x2 to i32
|
|
|
|
store i32 %x2.cast, i32* %c.cast
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test17(i8** %x, i8 %y) {
|
|
|
|
; Check that in cases similar to @test16 we don't try to rewrite a load when
|
|
|
|
; its only use is a store but it is used as the pointer to that store rather
|
|
|
|
; than the value.
|
|
|
|
;
|
|
|
|
; CHECK-LABEL: @test17(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: %[[L:.*]] = load i8*, i8**
|
2015-01-22 13:08:12 +08:00
|
|
|
; CHECK: store i8 %y, i8* %[[L]]
|
|
|
|
|
|
|
|
entry:
|
2015-02-28 05:17:42 +08:00
|
|
|
%x.load = load i8*, i8** %x
|
2015-01-22 13:08:12 +08:00
|
|
|
store i8 %y, i8* %x.load
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|