2002-05-07 01:43:38 +08:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
|
|
|
;
|
2009-11-02 03:22:20 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2002-05-07 01:43:38 +08:00
|
|
|
|
2009-11-09 03:23:30 +08:00
|
|
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128:n8:16:32:64"
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test1(i32 %A, i1 %b) {
|
|
|
|
BB0:
|
|
|
|
br i1 %b, label %BB1, label %BB2
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB1:
|
2008-03-01 17:15:35 +08:00
|
|
|
; Combine away one argument PHI nodes
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %A, %BB0 ]
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2002-05-07 01:43:38 +08:00
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB2:
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %A
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: BB1:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
2002-05-07 01:43:38 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test2(i32 %A, i1 %b) {
|
|
|
|
BB0:
|
|
|
|
br i1 %b, label %BB1, label %BB2
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB1:
|
2008-03-01 17:15:35 +08:00
|
|
|
br label %BB2
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB2:
|
2008-03-01 17:15:35 +08:00
|
|
|
; Combine away PHI nodes with same values
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ]
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
2002-08-20 23:27:45 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test3(i32 %A, i1 %b) {
|
|
|
|
BB0:
|
|
|
|
br label %Loop
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
Loop:
|
2008-03-01 17:15:35 +08:00
|
|
|
; PHI has same value always.
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %B, %Loop ]
|
2008-03-01 17:15:35 +08:00
|
|
|
br i1 %b, label %Loop, label %Exit
|
2002-08-23 05:26:15 +08:00
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
Exit:
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
2002-08-23 05:26:15 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test4(i1 %b) {
|
|
|
|
BB0:
|
|
|
|
; Loop is unreachable
|
|
|
|
ret i32 7
|
2002-08-23 05:26:15 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
Loop: ; preds = %L2, %Loop
|
|
|
|
; PHI has same value always.
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %B, %L2 ], [ %B, %Loop ]
|
2008-03-01 17:15:35 +08:00
|
|
|
br i1 %b, label %L2, label %Loop
|
|
|
|
|
|
|
|
L2: ; preds = %Loop
|
|
|
|
br label %Loop
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
2002-08-23 05:26:15 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test5(i32 %A, i1 %b) {
|
|
|
|
BB0:
|
|
|
|
br label %Loop
|
|
|
|
|
|
|
|
Loop: ; preds = %Loop, %BB0
|
|
|
|
; PHI has same value always.
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ undef, %Loop ]
|
2008-03-01 17:15:35 +08:00
|
|
|
br i1 %b, label %Loop, label %Exit
|
2004-11-15 01:54:27 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
2004-11-15 01:54:27 +08:00
|
|
|
}
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
define i32 @test6(i16 %A, i1 %b) {
|
2004-11-15 03:12:17 +08:00
|
|
|
BB0:
|
2009-11-02 03:22:20 +08:00
|
|
|
%X = zext i16 %A to i32
|
2008-03-01 17:15:35 +08:00
|
|
|
br i1 %b, label %BB1, label %BB2
|
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB1:
|
|
|
|
%Y = zext i16 %A to i32
|
2004-11-15 03:12:17 +08:00
|
|
|
br label %BB2
|
2008-03-01 17:15:35 +08:00
|
|
|
|
2009-11-02 03:22:20 +08:00
|
|
|
BB2:
|
2008-03-01 17:15:35 +08:00
|
|
|
;; Suck casts into phi
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test6(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK: zext i16 %A to i32
|
|
|
|
; CHECK-NEXT: ret i32
|
2004-11-15 03:12:17 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test7(i32 %A, i1 %b) {
|
|
|
|
BB0:
|
|
|
|
br label %Loop
|
|
|
|
|
|
|
|
Loop: ; preds = %Loop, %BB0
|
|
|
|
; PHI is dead.
|
2009-11-02 03:22:20 +08:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %C, %Loop ]
|
|
|
|
%C = add i32 %B, 123
|
2008-03-01 17:15:35 +08:00
|
|
|
br i1 %b, label %Loop, label %Exit
|
2007-01-15 15:29:29 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i32 0
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test7(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
2007-01-15 15:29:29 +08:00
|
|
|
}
|
|
|
|
|
Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves. This triggers 647 times on 403.gcc
and makes the .s file much much nicer. For example before:
je LBB1_87 ## bb78
LBB1_62: ## bb77
leal 84(%esi), %eax
LBB1_63: ## bb79
movl (%eax), %eax
...
LBB1_87: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
jmp LBB1_62 ## bb77
after:
jne LBB1_63 ## bb79
LBB1_62: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
LBB1_63: ## bb79
movl 84(%esi), %eax
The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):
br i1 %tmp233, label %bb78, label %bb77
bb77:
%tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb78:
call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
%tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb79:
%iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]
%iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in
llvm-svn: 60322
2008-12-01 10:34:36 +08:00
|
|
|
define i32* @test8({ i32, i32 } *%A, i1 %b) {
|
|
|
|
BB0:
|
[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
|
|
|
%X = getelementptr inbounds { i32, i32 }, { i32, i32 } *%A, i32 0, i32 1
|
Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves. This triggers 647 times on 403.gcc
and makes the .s file much much nicer. For example before:
je LBB1_87 ## bb78
LBB1_62: ## bb77
leal 84(%esi), %eax
LBB1_63: ## bb79
movl (%eax), %eax
...
LBB1_87: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
jmp LBB1_62 ## bb77
after:
jne LBB1_63 ## bb79
LBB1_62: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
LBB1_63: ## bb79
movl 84(%esi), %eax
The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):
br i1 %tmp233, label %bb78, label %bb77
bb77:
%tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb78:
call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
%tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb79:
%iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]
%iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in
llvm-svn: 60322
2008-12-01 10:34:36 +08:00
|
|
|
br i1 %b, label %BB1, label %BB2
|
|
|
|
|
|
|
|
BB1:
|
[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
|
|
|
%Y = getelementptr { i32, i32 }, { i32, i32 } *%A, i32 0, i32 1
|
Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves. This triggers 647 times on 403.gcc
and makes the .s file much much nicer. For example before:
je LBB1_87 ## bb78
LBB1_62: ## bb77
leal 84(%esi), %eax
LBB1_63: ## bb79
movl (%eax), %eax
...
LBB1_87: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
jmp LBB1_62 ## bb77
after:
jne LBB1_63 ## bb79
LBB1_62: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
LBB1_63: ## bb79
movl 84(%esi), %eax
The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):
br i1 %tmp233, label %bb78, label %bb77
bb77:
%tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb78:
call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
%tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb79:
%iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]
%iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in
llvm-svn: 60322
2008-12-01 10:34:36 +08:00
|
|
|
br label %BB2
|
|
|
|
|
|
|
|
BB2:
|
|
|
|
;; Suck GEPs into phi
|
|
|
|
%B = phi i32* [ %X, %BB0 ], [ %Y, %BB1 ]
|
|
|
|
ret i32* %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test8(
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK-NOT: phi
|
|
|
|
; CHECK: BB2:
|
[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: %B = getelementptr { i32, i32 }, { i32, i32 }* %A
|
2009-11-02 03:22:20 +08:00
|
|
|
; CHECK-NEXT: ret i32* %B
|
Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves. This triggers 647 times on 403.gcc
and makes the .s file much much nicer. For example before:
je LBB1_87 ## bb78
LBB1_62: ## bb77
leal 84(%esi), %eax
LBB1_63: ## bb79
movl (%eax), %eax
...
LBB1_87: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
jmp LBB1_62 ## bb77
after:
jne LBB1_63 ## bb79
LBB1_62: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
LBB1_63: ## bb79
movl 84(%esi), %eax
The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):
br i1 %tmp233, label %bb78, label %bb77
bb77:
%tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb78:
call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
%tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb79:
%iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]
%iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in
llvm-svn: 60322
2008-12-01 10:34:36 +08:00
|
|
|
}
|
|
|
|
|
2009-11-02 03:50:13 +08:00
|
|
|
define i32 @test9(i32* %A, i32* %B) {
|
|
|
|
entry:
|
|
|
|
%c = icmp eq i32* %A, null
|
|
|
|
br i1 %c, label %bb1, label %bb
|
|
|
|
|
|
|
|
bb:
|
2015-02-28 05:17:42 +08:00
|
|
|
%C = load i32, i32* %B, align 1
|
2009-11-02 03:50:13 +08:00
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb1:
|
2015-02-28 05:17:42 +08:00
|
|
|
%D = load i32, i32* %A, align 1
|
2009-11-02 03:50:13 +08:00
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb2:
|
|
|
|
%E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
|
|
|
|
ret i32 %E
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test9(
|
2009-11-02 03:50:13 +08:00
|
|
|
; CHECK: bb2:
|
|
|
|
; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %E = load i32, i32* %{{[^,]*}}, align 1
|
2009-11-02 03:50:13 +08:00
|
|
|
; CHECK-NEXT: ret i32 %E
|
2008-03-01 17:15:35 +08:00
|
|
|
|
2009-11-02 03:50:13 +08:00
|
|
|
}
|
2009-11-02 04:07:07 +08:00
|
|
|
|
|
|
|
define i32 @test10(i32* %A, i32* %B) {
|
|
|
|
entry:
|
|
|
|
%c = icmp eq i32* %A, null
|
|
|
|
br i1 %c, label %bb1, label %bb
|
|
|
|
|
|
|
|
bb:
|
2015-02-28 05:17:42 +08:00
|
|
|
%C = load i32, i32* %B, align 16
|
2009-11-02 04:07:07 +08:00
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb1:
|
2015-02-28 05:17:42 +08:00
|
|
|
%D = load i32, i32* %A, align 32
|
2009-11-02 04:07:07 +08:00
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb2:
|
|
|
|
%E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
|
|
|
|
ret i32 %E
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test10(
|
2009-11-02 04:07:07 +08:00
|
|
|
; CHECK: bb2:
|
|
|
|
; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %E = load i32, i32* %{{[^,]*}}, align 16
|
2009-11-02 04:07:07 +08:00
|
|
|
; CHECK-NEXT: ret i32 %E
|
2009-11-02 04:10:11 +08:00
|
|
|
}
|
|
|
|
|
2009-11-02 04:07:07 +08:00
|
|
|
|
2009-11-02 04:10:11 +08:00
|
|
|
; PR1777
|
|
|
|
declare i1 @test11a()
|
|
|
|
|
|
|
|
define i1 @test11() {
|
|
|
|
entry:
|
|
|
|
%a = alloca i32
|
2011-04-16 22:31:50 +08:00
|
|
|
%i = ptrtoint i32* %a to i64
|
2009-11-02 04:10:11 +08:00
|
|
|
%b = call i1 @test11a()
|
|
|
|
br i1 %b, label %one, label %two
|
|
|
|
|
|
|
|
one:
|
2011-04-16 22:31:50 +08:00
|
|
|
%x = phi i64 [%i, %entry], [%y, %two]
|
2009-11-02 04:10:11 +08:00
|
|
|
%c = call i1 @test11a()
|
|
|
|
br i1 %c, label %two, label %end
|
|
|
|
|
|
|
|
two:
|
2011-04-16 22:31:50 +08:00
|
|
|
%y = phi i64 [%i, %entry], [%x, %one]
|
2009-11-02 04:10:11 +08:00
|
|
|
%d = call i1 @test11a()
|
|
|
|
br i1 %d, label %one, label %end
|
|
|
|
|
|
|
|
end:
|
2011-04-16 22:31:50 +08:00
|
|
|
%f = phi i64 [ %x, %one], [%y, %two]
|
2009-11-02 04:10:11 +08:00
|
|
|
; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
|
|
|
|
; even though %f must equal %i at this point
|
2011-04-16 22:31:50 +08:00
|
|
|
%g = inttoptr i64 %f to i32*
|
2009-11-02 04:10:11 +08:00
|
|
|
store i32 10, i32* %g
|
|
|
|
%z = call i1 @test11a()
|
|
|
|
ret i1 %z
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test11(
|
2009-11-02 04:10:11 +08:00
|
|
|
; CHECK-NOT: phi i32
|
|
|
|
; CHECK: ret i1 %z
|
2009-11-02 04:07:07 +08:00
|
|
|
}
|
|
|
|
|
2009-11-09 03:23:30 +08:00
|
|
|
|
|
|
|
define i64 @test12(i1 %cond, i8* %Ptr, i64 %Val) {
|
|
|
|
entry:
|
|
|
|
%tmp41 = ptrtoint i8* %Ptr to i64
|
|
|
|
%tmp42 = zext i64 %tmp41 to i128
|
|
|
|
br i1 %cond, label %end, label %two
|
|
|
|
|
|
|
|
two:
|
|
|
|
%tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
|
|
|
|
%tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
|
|
|
|
%ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
|
|
|
|
br label %end
|
|
|
|
|
|
|
|
end:
|
|
|
|
%tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
|
|
|
|
%tmp32 = trunc i128 %tmp869.0 to i64 ; <i64> [#uses=1]
|
|
|
|
%tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
|
|
|
|
%tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
|
|
|
|
|
|
|
|
%tmp2 = add i64 %tmp32, %tmp30
|
|
|
|
ret i64 %tmp2
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test12(
|
2009-11-09 05:20:06 +08:00
|
|
|
; CHECK-NOT: zext
|
|
|
|
; CHECK: end:
|
2015-08-17 11:11:26 +08:00
|
|
|
; CHECK-NEXT: phi i64 [ 0, %entry ], [ %Val, %two ]
|
2009-11-09 05:20:06 +08:00
|
|
|
; CHECK-NOT: phi
|
|
|
|
; CHECK: ret i64
|
2009-11-09 03:23:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
declare void @test13f(double, i32)
|
|
|
|
|
|
|
|
define void @test13(i1 %cond, i32 %V1, double %Vald) {
|
|
|
|
entry:
|
|
|
|
%tmp42 = zext i32 %V1 to i128
|
|
|
|
br i1 %cond, label %end, label %two
|
|
|
|
|
|
|
|
two:
|
|
|
|
%Val = bitcast double %Vald to i64
|
|
|
|
%tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
|
|
|
|
%tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
|
|
|
|
%ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
|
|
|
|
br label %end
|
|
|
|
|
|
|
|
end:
|
|
|
|
%tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
|
|
|
|
%tmp32 = trunc i128 %tmp869.0 to i32
|
|
|
|
%tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
|
|
|
|
%tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
|
|
|
|
%tmp31 = bitcast i64 %tmp30 to double
|
|
|
|
|
|
|
|
call void @test13f(double %tmp31, i32 %tmp32)
|
|
|
|
ret void
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test13(
|
2009-11-09 05:20:06 +08:00
|
|
|
; CHECK-NOT: zext
|
|
|
|
; CHECK: end:
|
|
|
|
; CHECK-NEXT: phi double [ 0.000000e+00, %entry ], [ %Vald, %two ]
|
|
|
|
; CHECK-NEXT: call void @test13f(double {{[^,]*}}, i32 %V1)
|
|
|
|
; CHECK: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define i640 @test14a(i320 %A, i320 %B, i1 %b1) {
|
|
|
|
BB0:
|
|
|
|
%a = zext i320 %A to i640
|
|
|
|
%b = zext i320 %B to i640
|
|
|
|
br label %Loop
|
|
|
|
|
|
|
|
Loop:
|
|
|
|
%C = phi i640 [ %a, %BB0 ], [ %b, %Loop ]
|
|
|
|
br i1 %b1, label %Loop, label %Exit
|
|
|
|
|
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i640 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test14a(
|
2009-11-09 05:20:06 +08:00
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: phi i320
|
2009-11-09 03:23:30 +08:00
|
|
|
}
|
|
|
|
|
2009-11-09 05:20:06 +08:00
|
|
|
define i160 @test14b(i320 %A, i320 %B, i1 %b1) {
|
|
|
|
BB0:
|
|
|
|
%a = trunc i320 %A to i160
|
|
|
|
%b = trunc i320 %B to i160
|
|
|
|
br label %Loop
|
|
|
|
|
|
|
|
Loop:
|
|
|
|
%C = phi i160 [ %a, %BB0 ], [ %b, %Loop ]
|
|
|
|
br i1 %b1, label %Loop, label %Exit
|
|
|
|
|
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i160 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test14b(
|
2009-11-09 05:20:06 +08:00
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: phi i160
|
|
|
|
}
|
2009-11-09 09:38:00 +08:00
|
|
|
|
|
|
|
declare i64 @test15a(i64)
|
|
|
|
|
|
|
|
define i64 @test15b(i64 %A, i1 %b) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test15b(
|
2009-11-09 09:38:00 +08:00
|
|
|
entry:
|
|
|
|
%i0 = zext i64 %A to i128
|
|
|
|
%i1 = shl i128 %i0, 64
|
|
|
|
%i = or i128 %i1, %i0
|
|
|
|
br i1 %b, label %one, label %two
|
|
|
|
; CHECK: entry:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
|
|
|
|
|
|
|
one:
|
|
|
|
%x = phi i128 [%i, %entry], [%y, %two]
|
|
|
|
%x1 = lshr i128 %x, 64
|
|
|
|
%x2 = trunc i128 %x1 to i64
|
|
|
|
%c = call i64 @test15a(i64 %x2)
|
|
|
|
%c1 = zext i64 %c to i128
|
|
|
|
br label %two
|
|
|
|
|
|
|
|
; CHECK: one:
|
|
|
|
; CHECK-NEXT: phi i64
|
|
|
|
; CHECK-NEXT: %c = call i64 @test15a
|
|
|
|
|
|
|
|
two:
|
|
|
|
%y = phi i128 [%i, %entry], [%c1, %one]
|
|
|
|
%y1 = lshr i128 %y, 64
|
|
|
|
%y2 = trunc i128 %y1 to i64
|
|
|
|
%d = call i64 @test15a(i64 %y2)
|
|
|
|
%d1 = trunc i64 %d to i1
|
|
|
|
br i1 %d1, label %one, label %end
|
|
|
|
|
|
|
|
; CHECK: two:
|
|
|
|
; CHECK-NEXT: phi i64
|
|
|
|
; CHECK-NEXT: phi i64
|
|
|
|
; CHECK-NEXT: %d = call i64 @test15a
|
|
|
|
|
|
|
|
end:
|
|
|
|
%g = trunc i128 %y to i64
|
|
|
|
ret i64 %g
|
|
|
|
; CHECK: end:
|
|
|
|
; CHECK-NEXT: ret i64
|
|
|
|
}
|
|
|
|
|
2010-03-06 02:53:28 +08:00
|
|
|
; PR6512 - Shouldn't merge loads from different addr spaces.
|
|
|
|
define i32 @test16(i32 addrspace(1)* %pointer1, i32 %flag, i32* %pointer2)
|
|
|
|
nounwind {
|
|
|
|
entry:
|
|
|
|
%retval = alloca i32, align 4 ; <i32*> [#uses=2]
|
|
|
|
%pointer1.addr = alloca i32 addrspace(1)*, align 4 ; <i32 addrspace(1)**>
|
|
|
|
%flag.addr = alloca i32, align 4 ; <i32*> [#uses=2]
|
|
|
|
%pointer2.addr = alloca i32*, align 4 ; <i32**> [#uses=2]
|
|
|
|
%res = alloca i32, align 4 ; <i32*> [#uses=4]
|
|
|
|
store i32 addrspace(1)* %pointer1, i32 addrspace(1)** %pointer1.addr
|
|
|
|
store i32 %flag, i32* %flag.addr
|
|
|
|
store i32* %pointer2, i32** %pointer2.addr
|
|
|
|
store i32 10, i32* %res
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i32, i32* %flag.addr ; <i32> [#uses=1]
|
2010-03-06 02:53:28 +08:00
|
|
|
%tobool = icmp ne i32 %tmp, 0 ; <i1> [#uses=1]
|
|
|
|
br i1 %tobool, label %if.then, label %if.else
|
|
|
|
|
|
|
|
return: ; preds = %if.end
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp7 = load i32, i32* %retval ; <i32> [#uses=1]
|
2010-03-06 02:53:28 +08:00
|
|
|
ret i32 %tmp7
|
|
|
|
|
|
|
|
if.end: ; preds = %if.else, %if.then
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp6 = load i32, i32* %res ; <i32> [#uses=1]
|
2010-03-06 02:53:28 +08:00
|
|
|
store i32 %tmp6, i32* %retval
|
|
|
|
br label %return
|
|
|
|
|
|
|
|
if.then: ; preds = %entry
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp1 = load i32 addrspace(1)*, i32 addrspace(1)** %pointer1.addr ; <i32 addrspace(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
|
|
|
%arrayidx = getelementptr i32, i32 addrspace(1)* %tmp1, i32 0 ; <i32 addrspace(1)*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp2 = load i32, i32 addrspace(1)* %arrayidx ; <i32> [#uses=1]
|
2010-03-06 02:53:28 +08:00
|
|
|
store i32 %tmp2, i32* %res
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.else: ; preds = %entry
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp3 = load i32*, i32** %pointer2.addr ; <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
|
|
|
%arrayidx4 = getelementptr i32, i32* %tmp3, i32 0 ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp5 = load i32, i32* %arrayidx4 ; <i32> [#uses=1]
|
2010-03-06 02:53:28 +08:00
|
|
|
store i32 %tmp5, i32* %res
|
|
|
|
br label %if.end
|
|
|
|
}
|
2010-09-04 02:33:08 +08:00
|
|
|
|
|
|
|
; PR4413
|
|
|
|
declare i32 @ext()
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test17(
|
2010-09-04 02:33:08 +08:00
|
|
|
define i32 @test17(i1 %a) {
|
|
|
|
entry:
|
|
|
|
br i1 %a, label %bb1, label %bb2
|
|
|
|
|
|
|
|
bb1: ; preds = %entry
|
|
|
|
%0 = tail call i32 @ext() ; <i32> [#uses=1]
|
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb2: ; preds = %bb1, %entry
|
|
|
|
%cond = phi i1 [ true, %bb1 ], [ false, %entry ] ; <i1> [#uses=1]
|
|
|
|
; CHECK-NOT: %val = phi i32 [ %0, %bb1 ], [ 0, %entry ]
|
|
|
|
%val = phi i32 [ %0, %bb1 ], [ 0, %entry ] ; <i32> [#uses=1]
|
|
|
|
%res = select i1 %cond, i32 %val, i32 0 ; <i32> [#uses=1]
|
|
|
|
; CHECK: ret i32 %cond
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
2010-11-16 00:43:28 +08:00
|
|
|
define i1 @test18(i1 %cond) {
|
|
|
|
%zero = alloca i32
|
|
|
|
%one = alloca i32
|
|
|
|
br i1 %cond, label %true, label %false
|
|
|
|
true:
|
|
|
|
br label %ret
|
|
|
|
false:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%ptr = phi i32* [ %zero, %true ] , [ %one, %false ]
|
|
|
|
%isnull = icmp eq i32* %ptr, null
|
|
|
|
ret i1 %isnull
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test18(
|
2010-11-16 00:43:28 +08:00
|
|
|
; CHECK: ret i1 false
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @test19(i1 %cond, double %x) {
|
|
|
|
br i1 %cond, label %true, label %false
|
|
|
|
true:
|
|
|
|
br label %ret
|
|
|
|
false:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%p = phi double [ %x, %true ], [ 0x7FF0000000000000, %false ]; RHS = +infty
|
|
|
|
%cmp = fcmp ule double %x, %p
|
|
|
|
ret i1 %cmp
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test19(
|
2010-11-16 00:43:28 +08:00
|
|
|
; CHECK: ret i1 true
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @test20(i1 %cond) {
|
|
|
|
%a = alloca i32
|
|
|
|
%b = alloca i32
|
|
|
|
%c = alloca i32
|
|
|
|
br i1 %cond, label %true, label %false
|
|
|
|
true:
|
|
|
|
br label %ret
|
|
|
|
false:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%p = phi i32* [ %a, %true ], [ %b, %false ]
|
|
|
|
%r = icmp eq i32* %p, %c
|
|
|
|
ret i1 %r
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test20(
|
2010-11-16 00:43:28 +08:00
|
|
|
; CHECK: ret i1 false
|
|
|
|
}
|
2010-11-16 01:52:45 +08:00
|
|
|
|
|
|
|
define i1 @test21(i1 %c1, i1 %c2) {
|
|
|
|
%a = alloca i32
|
|
|
|
%b = alloca i32
|
|
|
|
%c = alloca i32
|
|
|
|
br i1 %c1, label %true, label %false
|
|
|
|
true:
|
|
|
|
br label %loop
|
|
|
|
false:
|
|
|
|
br label %loop
|
|
|
|
loop:
|
|
|
|
%p = phi i32* [ %a, %true ], [ %b, %false ], [ %p, %loop ]
|
|
|
|
%r = icmp eq i32* %p, %c
|
|
|
|
br i1 %c2, label %ret, label %loop
|
|
|
|
ret:
|
|
|
|
ret i1 %r
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test21(
|
2010-11-16 01:52:45 +08:00
|
|
|
; CHECK: ret i1 false
|
|
|
|
}
|
2010-11-16 20:16:38 +08:00
|
|
|
|
|
|
|
define void @test22() {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test22(
|
2010-11-16 20:16:38 +08:00
|
|
|
entry:
|
|
|
|
br label %loop
|
|
|
|
loop:
|
|
|
|
%phi = phi i32 [ 0, %entry ], [ %y, %loop ]
|
|
|
|
%y = add i32 %phi, 1
|
|
|
|
%o = or i32 %y, %phi
|
|
|
|
%e = icmp eq i32 %o, %y
|
|
|
|
br i1 %e, label %loop, label %ret
|
|
|
|
; CHECK: br i1 %e
|
|
|
|
ret:
|
|
|
|
ret void
|
|
|
|
}
|
2011-01-16 13:28:59 +08:00
|
|
|
|
|
|
|
define i32 @test23(i32 %A, i1 %b, i32 * %P) {
|
|
|
|
BB0:
|
|
|
|
br label %Loop
|
|
|
|
|
|
|
|
Loop: ; preds = %Loop, %BB0
|
|
|
|
; PHI has same value always.
|
|
|
|
%B = phi i32 [ %A, %BB0 ], [ 42, %Loop ]
|
|
|
|
%D = add i32 %B, 19
|
|
|
|
store i32 %D, i32* %P
|
|
|
|
br i1 %b, label %Loop, label %Exit
|
|
|
|
|
|
|
|
Exit: ; preds = %Loop
|
|
|
|
%E = add i32 %B, 19
|
|
|
|
ret i32 %E
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test23(
|
2011-01-16 13:28:59 +08:00
|
|
|
; CHECK: %phitmp = add i32 %A, 19
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: %B = phi i32 [ %phitmp, %BB0 ], [ 61, %Loop ]
|
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: ret i32 %B
|
|
|
|
}
|
2011-02-18 06:21:26 +08:00
|
|
|
|
2011-02-18 07:01:49 +08:00
|
|
|
define i32 @test24(i32 %A, i1 %cond) {
|
|
|
|
BB0:
|
|
|
|
%X = add nuw nsw i32 %A, 1
|
|
|
|
br i1 %cond, label %BB1, label %BB2
|
|
|
|
|
|
|
|
BB1:
|
|
|
|
%Y = add nuw i32 %A, 1
|
|
|
|
br label %BB2
|
|
|
|
|
|
|
|
BB2:
|
|
|
|
%C = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
|
|
|
|
ret i32 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test24(
|
2011-02-18 07:01:49 +08:00
|
|
|
; CHECK-NOT: phi
|
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK-NEXT: %C = add nuw i32 %A, 1
|
|
|
|
; CHECK-NEXT: ret i32 %C
|
|
|
|
}
|
2011-04-16 22:31:50 +08:00
|
|
|
|
|
|
|
; Same as test11, but used to be missed due to a bug.
|
|
|
|
declare i1 @test25a()
|
|
|
|
|
|
|
|
define i1 @test25() {
|
|
|
|
entry:
|
|
|
|
%a = alloca i32
|
|
|
|
%i = ptrtoint i32* %a to i64
|
|
|
|
%b = call i1 @test25a()
|
|
|
|
br i1 %b, label %one, label %two
|
|
|
|
|
|
|
|
one:
|
|
|
|
%x = phi i64 [%y, %two], [%i, %entry]
|
|
|
|
%c = call i1 @test25a()
|
|
|
|
br i1 %c, label %two, label %end
|
|
|
|
|
|
|
|
two:
|
|
|
|
%y = phi i64 [%x, %one], [%i, %entry]
|
|
|
|
%d = call i1 @test25a()
|
|
|
|
br i1 %d, label %one, label %end
|
|
|
|
|
|
|
|
end:
|
|
|
|
%f = phi i64 [ %x, %one], [%y, %two]
|
|
|
|
; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
|
|
|
|
; even though %f must equal %i at this point
|
|
|
|
%g = inttoptr i64 %f to i32*
|
|
|
|
store i32 10, i32* %g
|
|
|
|
%z = call i1 @test25a()
|
|
|
|
ret i1 %z
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test25(
|
2011-04-16 22:31:50 +08:00
|
|
|
; CHECK-NOT: phi i32
|
|
|
|
; CHECK: ret i1 %z
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i1 @test26a()
|
|
|
|
|
|
|
|
define i1 @test26(i32 %n) {
|
|
|
|
entry:
|
|
|
|
%a = alloca i32
|
|
|
|
%i = ptrtoint i32* %a to i64
|
|
|
|
%b = call i1 @test26a()
|
|
|
|
br label %one
|
|
|
|
|
|
|
|
one:
|
|
|
|
%x = phi i64 [%y, %two], [%w, %three], [%i, %entry]
|
|
|
|
%c = call i1 @test26a()
|
|
|
|
switch i32 %n, label %end [
|
|
|
|
i32 2, label %two
|
|
|
|
i32 3, label %three
|
|
|
|
]
|
|
|
|
|
|
|
|
two:
|
|
|
|
%y = phi i64 [%x, %one], [%w, %three]
|
|
|
|
%d = call i1 @test26a()
|
|
|
|
switch i32 %n, label %end [
|
|
|
|
i32 10, label %one
|
|
|
|
i32 30, label %three
|
|
|
|
]
|
|
|
|
|
|
|
|
three:
|
|
|
|
%w = phi i64 [%y, %two], [%x, %one]
|
|
|
|
%e = call i1 @test26a()
|
|
|
|
br i1 %e, label %one, label %two
|
|
|
|
|
|
|
|
end:
|
|
|
|
%f = phi i64 [ %x, %one], [%y, %two]
|
|
|
|
; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
|
|
|
|
; even though %f must equal %i at this point
|
|
|
|
%g = inttoptr i64 %f to i32*
|
|
|
|
store i32 10, i32* %g
|
|
|
|
%z = call i1 @test26a()
|
|
|
|
ret i1 %z
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test26(
|
2011-04-16 22:31:50 +08:00
|
|
|
; CHECK-NOT: phi i32
|
|
|
|
; CHECK: ret i1 %z
|
|
|
|
}
|
2012-04-28 01:50:22 +08:00
|
|
|
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test27(
|
2012-04-28 01:50:22 +08:00
|
|
|
; CHECK: ret i32 undef
|
|
|
|
define i32 @test27(i1 %b) {
|
|
|
|
entry:
|
|
|
|
br label %done
|
|
|
|
done:
|
|
|
|
%y = phi i32 [ undef, %entry ]
|
|
|
|
ret i32 %y
|
|
|
|
}
|
2015-09-28 04:34:31 +08:00
|
|
|
|
|
|
|
; We should be able to fold the zexts to the other side of the phi
|
|
|
|
; even though there's a constant value input to the phi. This is
|
|
|
|
; because we can shrink that constant to the smaller phi type.
|
|
|
|
|
|
|
|
define i1 @PR24766(i8 %x1, i8 %x2, i8 %condition) {
|
|
|
|
entry:
|
|
|
|
%conv = sext i8 %condition to i32
|
|
|
|
switch i32 %conv, label %epilog [
|
|
|
|
i32 0, label %sw1
|
|
|
|
i32 1, label %sw2
|
|
|
|
]
|
|
|
|
|
|
|
|
sw1:
|
|
|
|
%cmp1 = icmp eq i8 %x1, %x2
|
|
|
|
%frombool1 = zext i1 %cmp1 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
%cmp2 = icmp sle i8 %x1, %x2
|
|
|
|
%frombool2 = zext i1 %cmp2 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
epilog:
|
|
|
|
%conditionMet = phi i8 [ 0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ]
|
|
|
|
%tobool = icmp ne i8 %conditionMet, 0
|
|
|
|
ret i1 %tobool
|
|
|
|
|
|
|
|
; CHECK-LABEL: @PR24766(
|
|
|
|
; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ]
|
|
|
|
; CHECK-NEXT: ret i1 %[[RES]]
|
|
|
|
}
|
|
|
|
|
|
|
|
; Same as above (a phi with more than 2 operands), but no constants
|
|
|
|
|
|
|
|
define i1 @PR24766_no_constants(i8 %x1, i8 %x2, i8 %condition, i1 %another_condition) {
|
|
|
|
entry:
|
|
|
|
%frombool0 = zext i1 %another_condition to i8
|
|
|
|
%conv = sext i8 %condition to i32
|
|
|
|
switch i32 %conv, label %epilog [
|
|
|
|
i32 0, label %sw1
|
|
|
|
i32 1, label %sw2
|
|
|
|
]
|
|
|
|
|
|
|
|
sw1:
|
|
|
|
%cmp1 = icmp eq i8 %x1, %x2
|
|
|
|
%frombool1 = zext i1 %cmp1 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
%cmp2 = icmp sle i8 %x1, %x2
|
|
|
|
%frombool2 = zext i1 %cmp2 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
epilog:
|
|
|
|
%conditionMet = phi i8 [ %frombool0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ]
|
|
|
|
%tobool = icmp ne i8 %conditionMet, 0
|
|
|
|
ret i1 %tobool
|
|
|
|
|
|
|
|
; CHECK-LABEL: @PR24766_no_constants(
|
|
|
|
; CHECK: %[[RES:.*]] = phi i1 [ %another_condition, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ]
|
|
|
|
; CHECK-NEXT: ret i1 %[[RES]]
|
|
|
|
}
|
|
|
|
|
|
|
|
; Same as above (a phi with more than 2 operands), but two constants
|
|
|
|
|
|
|
|
define i1 @PR24766_two_constants(i8 %x1, i8 %x2, i8 %condition) {
|
|
|
|
entry:
|
|
|
|
%conv = sext i8 %condition to i32
|
|
|
|
switch i32 %conv, label %epilog [
|
|
|
|
i32 0, label %sw1
|
|
|
|
i32 1, label %sw2
|
|
|
|
]
|
|
|
|
|
|
|
|
sw1:
|
|
|
|
%cmp1 = icmp eq i8 %x1, %x2
|
|
|
|
%frombool1 = zext i1 %cmp1 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
%cmp2 = icmp sle i8 %x1, %x2
|
|
|
|
%frombool2 = zext i1 %cmp2 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
epilog:
|
|
|
|
%conditionMet = phi i8 [ 0, %entry ], [ 1, %sw2 ], [ %frombool1, %sw1 ]
|
|
|
|
%tobool = icmp ne i8 %conditionMet, 0
|
|
|
|
ret i1 %tobool
|
|
|
|
|
|
|
|
; CHECK-LABEL: @PR24766_two_constants(
|
|
|
|
; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ true, %sw2 ], [ %cmp1, %sw1 ]
|
|
|
|
; CHECK-NEXT: ret i1 %[[RES]]
|
|
|
|
}
|
|
|
|
|
|
|
|
; Same as above (a phi with more than 2 operands), but two constants and two variables
|
|
|
|
|
|
|
|
define i1 @PR24766_two_constants_two_var(i8 %x1, i8 %x2, i8 %condition) {
|
|
|
|
entry:
|
|
|
|
%conv = sext i8 %condition to i32
|
|
|
|
switch i32 %conv, label %epilog [
|
|
|
|
i32 0, label %sw1
|
|
|
|
i32 1, label %sw2
|
|
|
|
i32 2, label %sw3
|
|
|
|
]
|
|
|
|
|
|
|
|
sw1:
|
|
|
|
%cmp1 = icmp eq i8 %x1, %x2
|
|
|
|
%frombool1 = zext i1 %cmp1 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
%cmp2 = icmp sle i8 %x1, %x2
|
|
|
|
%frombool2 = zext i1 %cmp2 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
sw3:
|
|
|
|
%cmp3 = icmp sge i8 %x1, %x2
|
|
|
|
%frombool3 = zext i1 %cmp3 to i8
|
|
|
|
br label %epilog
|
|
|
|
|
|
|
|
epilog:
|
|
|
|
%conditionMet = phi i8 [ 0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ], [ 1, %sw3 ]
|
|
|
|
%tobool = icmp ne i8 %conditionMet, 0
|
|
|
|
ret i1 %tobool
|
|
|
|
|
|
|
|
; CHECK-LABEL: @PR24766_two_constants_two_var(
|
|
|
|
; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ], [ true, %sw3 ]
|
|
|
|
; CHECK-NEXT: ret i1 %[[RES]]
|
|
|
|
}
|
|
|
|
|
2016-02-02 01:03:07 +08:00
|
|
|
; CHECK-LABEL: phi_allnonzeroconstant
|
|
|
|
; CHECK-NOT: phi i32
|
|
|
|
; CHECK: ret i1 false
|
|
|
|
define i1 @phi_allnonzeroconstant(i1 %c, i32 %a, i32 %b) {
|
|
|
|
entry:
|
|
|
|
br i1 %c, label %if.then, label %if.else
|
|
|
|
|
|
|
|
if.then: ; preds = %entry
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.else: ; preds = %entry
|
|
|
|
call void @dummy()
|
|
|
|
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.end: ; preds = %if.else, %if.then
|
|
|
|
%x.0 = phi i32 [ 1, %if.then ], [ 2, %if.else ]
|
|
|
|
%or = or i32 %x.0, %a
|
|
|
|
%cmp1 = icmp eq i32 %or, 0
|
|
|
|
ret i1 %cmp1
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void @dummy()
|
|
|
|
|
[InstCombine] Simplify a known nonzero incoming value of PHI
Summary:
When a PHI is used only to be compared with zero, it is possible to replace an
incoming value with any non-zero constant if the incoming value can be proved as
a known nonzero value. For example, in below code, we can replace the incoming value %v with
any non-zero constant based on the fact that the PHI is only used to be compared with zero
and %v is a known non-zero value:
%v = select %cond, 1, 2
%p = phi [%v, BB] ...
%c = icmp eq, %p, 0
Reviewers: mcrosier, jmolloy, sanjoy
Subscribers: hfinkel, mcrosier, majnemer, llvm-commits, haicheng, bmakam, mssimpso, gberry
Differential Revision: http://reviews.llvm.org/D16240
llvm-svn: 260530
2016-02-11 23:50:07 +08:00
|
|
|
; CHECK-LABEL: @phi_knownnonzero_eq
|
|
|
|
; CHECK-LABEL: if.then:
|
|
|
|
; CHECK-NOT: select
|
|
|
|
; CHECK-LABEL: if.end:
|
|
|
|
; CHECK: phi i32 [ 1, %if.then ]
|
|
|
|
define i1 @phi_knownnonzero_eq(i32 %n, i32 %s, i32* nocapture readonly %P) {
|
|
|
|
entry:
|
|
|
|
%tobool = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool, label %if.end, label %if.then
|
|
|
|
|
|
|
|
if.then: ; preds = %entry
|
|
|
|
%0 = load i32, i32* %P
|
|
|
|
%cmp = icmp eq i32 %n, %0
|
|
|
|
%1 = select i1 %cmp, i32 1, i32 2
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.end: ; preds = %entry, %if.then
|
|
|
|
%a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
|
|
|
|
%cmp1 = icmp eq i32 %a.0, 0
|
|
|
|
ret i1 %cmp1
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: @phi_knownnonzero_ne
|
|
|
|
; CHECK-LABEL: if.then:
|
|
|
|
; CHECK-NOT: select
|
|
|
|
; CHECK-LABEL: if.end:
|
|
|
|
; CHECK: phi i32 [ 1, %if.then ]
|
|
|
|
define i1 @phi_knownnonzero_ne(i32 %n, i32 %s, i32* nocapture readonly %P) {
|
|
|
|
entry:
|
|
|
|
%tobool = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool, label %if.end, label %if.then
|
|
|
|
|
|
|
|
if.then: ; preds = %entry
|
|
|
|
%0 = load i32, i32* %P
|
|
|
|
%cmp = icmp eq i32 %n, %0
|
|
|
|
%1 = select i1 %cmp, i32 1, i32 2
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.end: ; preds = %entry, %if.then
|
|
|
|
%a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
|
|
|
|
%cmp1 = icmp ne i32 %a.0, 0
|
|
|
|
ret i1 %cmp1
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: @phi_knownnonzero_eq_2
|
|
|
|
; CHECK-LABEL: if.then:
|
|
|
|
; CHECK-NOT: select
|
|
|
|
; CHECK-LABEL: if.end:
|
|
|
|
; CHECK: phi i32 [ 2, %if.else ]
|
|
|
|
define i1 @phi_knownnonzero_eq_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
|
|
|
|
entry:
|
|
|
|
%tobool = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool, label %if.then, label %if.end
|
|
|
|
|
|
|
|
if.then:
|
|
|
|
%tobool2 = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool2, label %if.else, label %if.end
|
|
|
|
|
|
|
|
if.else: ; preds = %entry
|
|
|
|
%0 = load i32, i32* %P
|
|
|
|
%cmp = icmp eq i32 %n, %0
|
|
|
|
%1 = select i1 %cmp, i32 1, i32 2
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.end: ; preds = %entry, %if.then
|
|
|
|
%a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
|
|
|
|
%cmp1 = icmp eq i32 %a.0, 0
|
|
|
|
ret i1 %cmp1
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: @phi_knownnonzero_ne_2
|
|
|
|
; CHECK-LABEL: if.then:
|
|
|
|
; CHECK-NOT: select
|
|
|
|
; CHECK-LABEL: if.end:
|
|
|
|
; CHECK: phi i32 [ 2, %if.else ]
|
|
|
|
define i1 @phi_knownnonzero_ne_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
|
|
|
|
entry:
|
|
|
|
%tobool = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool, label %if.then, label %if.end
|
|
|
|
|
|
|
|
if.then:
|
|
|
|
%tobool2 = icmp slt i32 %n, %s
|
|
|
|
br i1 %tobool2, label %if.else, label %if.end
|
|
|
|
|
|
|
|
if.else: ; preds = %entry
|
|
|
|
%0 = load i32, i32* %P
|
|
|
|
%cmp = icmp eq i32 %n, %0
|
|
|
|
%1 = select i1 %cmp, i32 1, i32 2
|
|
|
|
br label %if.end
|
|
|
|
|
|
|
|
if.end: ; preds = %entry, %if.then
|
|
|
|
%a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
|
|
|
|
%cmp1 = icmp ne i32 %a.0, 0
|
|
|
|
ret i1 %cmp1
|
|
|
|
}
|