2010-08-04 02:20:32 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2013-09-04 05:05:48 +08:00
|
|
|
target datalayout = "E-p:64:64:64-p1:32:32:32-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
|
2008-04-11 02:43:06 +08:00
|
|
|
|
|
|
|
; Instcombine should be able to prove vector alignment in the
|
|
|
|
; presence of a few mild address computation tricks.
|
|
|
|
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test0(
|
2010-08-04 02:20:32 +08:00
|
|
|
; CHECK: align 16
|
|
|
|
|
|
|
|
define void @test0(i8* %b, i64 %n, i64 %u, i64 %y) nounwind {
|
2008-04-11 02:43:06 +08:00
|
|
|
entry:
|
|
|
|
%c = ptrtoint i8* %b to i64
|
|
|
|
%d = and i64 %c, -16
|
|
|
|
%e = inttoptr i64 %d to double*
|
|
|
|
%v = mul i64 %u, 2
|
|
|
|
%z = and i64 %y, -2
|
|
|
|
%t1421 = icmp eq i64 %n, 0
|
|
|
|
br i1 %t1421, label %return, label %bb
|
|
|
|
|
|
|
|
bb:
|
|
|
|
%i = phi i64 [ %indvar.next, %bb ], [ 20, %entry ]
|
|
|
|
%j = mul i64 %i, %v
|
|
|
|
%h = add i64 %j, %z
|
[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
|
|
|
%t8 = getelementptr double, double* %e, i64 %h
|
2008-04-11 02:43:06 +08:00
|
|
|
%p = bitcast double* %t8 to <2 x double>*
|
|
|
|
store <2 x double><double 0.0, double 0.0>, <2 x double>* %p, align 8
|
|
|
|
%indvar.next = add i64 %i, 1
|
|
|
|
%exitcond = icmp eq i64 %indvar.next, %n
|
|
|
|
br i1 %exitcond, label %return, label %bb
|
|
|
|
|
|
|
|
return:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2010-08-04 02:20:32 +08:00
|
|
|
; When we see a unaligned load from an insufficiently aligned global or
|
|
|
|
; alloca, increase the alignment of the load, turning it into an aligned load.
|
|
|
|
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2010-08-04 02:20:32 +08:00
|
|
|
; CHECK: tmp = load
|
|
|
|
; CHECK: GLOBAL{{.*}}align 16
|
|
|
|
|
|
|
|
@GLOBAL = internal global [4 x i32] zeroinitializer
|
|
|
|
|
|
|
|
define <16 x i8> @test1(<2 x i64> %x) {
|
|
|
|
entry:
|
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>*), align 1
|
2010-08-04 02:20:32 +08:00
|
|
|
ret <16 x i8> %tmp
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:05:48 +08:00
|
|
|
@GLOBAL_as1 = internal addrspace(1) global [4 x i32] zeroinitializer
|
|
|
|
|
|
|
|
define <16 x i8> @test1_as1(<2 x i64> %x) {
|
|
|
|
; CHECK-LABEL: @test1_as1(
|
|
|
|
; CHECK: tmp = load
|
|
|
|
; CHECK: GLOBAL_as1{{.*}}align 16
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load <16 x i8>, <16 x i8> addrspace(1)* bitcast ([4 x i32] addrspace(1)* @GLOBAL_as1 to <16 x i8> addrspace(1)*), align 1
|
2013-09-04 05:05:48 +08:00
|
|
|
ret <16 x i8> %tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
@GLOBAL_as1_gep = internal addrspace(1) global [8 x i32] zeroinitializer
|
|
|
|
|
|
|
|
define <16 x i8> @test1_as1_gep(<2 x i64> %x) {
|
|
|
|
; CHECK-LABEL: @test1_as1_gep(
|
|
|
|
; CHECK: tmp = load
|
|
|
|
; CHECK: GLOBAL_as1_gep{{.*}}align 16
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load <16 x i8>, <16 x i8> addrspace(1)* bitcast (i32 addrspace(1)* getelementptr ([8 x i32] addrspace(1)* @GLOBAL_as1_gep, i16 0, i16 4) to <16 x i8> addrspace(1)*), align 1
|
2013-09-04 05:05:48 +08:00
|
|
|
ret <16 x i8> %tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-04 02:20:32 +08:00
|
|
|
; When a load or store lacks an explicit alignment, add one.
|
|
|
|
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: load double, double* %p, align 8
|
2010-08-04 02:20:32 +08:00
|
|
|
; CHECK: store double %n, double* %p, align 8
|
|
|
|
|
|
|
|
define double @test2(double* %p, double %n) nounwind {
|
2015-02-28 05:17:42 +08:00
|
|
|
%t = load double, double* %p
|
2010-08-04 02:20:32 +08:00
|
|
|
store double %n, double* %p
|
|
|
|
ret double %t
|
|
|
|
}
|
2012-10-04 21:36:31 +08:00
|
|
|
|
|
|
|
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
|
|
|
|
|
|
|
|
declare void @use(i8*)
|
|
|
|
|
|
|
|
%struct.s = type { i32, i32, i32, i32 }
|
|
|
|
|
|
|
|
define void @test3(%struct.s* sret %a4) {
|
|
|
|
; Check that the alignment is bumped up the alignment of the sret type.
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2012-10-04 21:36:31 +08:00
|
|
|
%a4.cast = bitcast %struct.s* %a4 to i8*
|
|
|
|
call void @llvm.memset.p0i8.i64(i8* %a4.cast, i8 0, i64 16, i32 1, i1 false)
|
|
|
|
; CHECK: call void @llvm.memset.p0i8.i64(i8* %a4.cast, i8 0, i64 16, i32 4, i1 false)
|
|
|
|
call void @use(i8* %a4.cast)
|
|
|
|
ret void
|
|
|
|
}
|