1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[IPConstantProp][NFCI] Improve and modernize tests

Summary:
This change is in preparation to reuse these test for the Attributor.
It mainly is to remove UB, make it clear what is tested, and use
"modern" run lines.

Reviewers: fhahn, efriedma, mssimpso, davide

Subscribers: bollu, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69747
This commit is contained in:
Johannes Doerfert 2019-11-01 23:36:41 -05:00
parent 8f1e06e258
commit bda2dd9fab
13 changed files with 99 additions and 64 deletions

View File

@ -1,7 +1,9 @@
; RUN: opt < %s -ipconstprop -S | grep "ret i32 %r"
; RUN: opt < %s -ipconstprop -S | FileCheck %s
; Should not propagate the result of a weak function.
; PR2411
; CHECK: ret i32 %r
define weak i32 @foo() nounwind {
entry:
ret i32 1

View File

@ -21,10 +21,10 @@ define internal i32 @vfu2(%struct.MYstr* byval align 4 %u) nounwind readonly {
entry:
%0 = getelementptr %struct.MYstr, %struct.MYstr* %u, i32 0, i32 1 ; <i32*> [#uses=1]
%1 = load i32, i32* %0
; CHECK: load i32, i32* getelementptr inbounds (%struct.MYstr, %struct.MYstr* @mystr, i32 0, i32 1)
; CHECK: %struct.MYstr* @mystr, i{{..}} 0, i32 1
%2 = getelementptr %struct.MYstr, %struct.MYstr* %u, i32 0, i32 0 ; <i8*> [#uses=1]
%3 = load i8, i8* %2
; CHECK: load i8, i8* getelementptr inbounds (%struct.MYstr, %struct.MYstr* @mystr, i32 0, i32 0)
; CHECK: %struct.MYstr* @mystr, i{{..}} 0, i32 0
%4 = zext i8 %3 to i32
%5 = add i32 %4, %1
ret i32 %5
@ -34,7 +34,7 @@ define i32 @unions() nounwind {
entry:
call void @vfu1(%struct.MYstr* byval align 4 @mystr) nounwind
%result = call i32 @vfu2(%struct.MYstr* byval align 4 @mystr) nounwind
; CHECK: ret i32 %result
ret i32 %result
}

View File

@ -1,9 +1,15 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
; RUN: opt < %s -S -ipsccp | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define i64 @fn2() {
; CHECK-LABEL: define {{[^@]+}}@fn2()
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL2:%.*]] = call i64 @fn1(i64 undef)
; CHECK-NEXT: ret i64 [[CALL2]]
;
entry:
%conv = sext i32 undef to i64
%div = sdiv i64 8, %conv
@ -11,16 +17,15 @@ entry:
ret i64 %call2
}
; CHECK-DAG: define i64 @fn2(
; CHECK: %[[CALL:.*]] = call i64 @fn1(i64 undef)
define internal i64 @fn1(i64 %p1) {
; CHECK-LABEL: define {{[^@]+}}@fn1
; CHECK-SAME: (i64 [[P1:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[COND:%.*]] = select i1 undef, i64 undef, i64 undef
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%tobool = icmp ne i64 %p1, 0
%cond = select i1 %tobool, i64 %p1, i64 %p1
ret i64 %cond
}
; CHECK-DAG: define internal i64 @fn1(
; CHECK: %[[SEL:.*]] = select i1 undef, i64 undef, i64 undef
; CHECK: ret i64 %[[SEL]]

View File

@ -1,8 +1,20 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
; RUN: opt < %s -S -ipsccp | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @fn2() {
define void @fn2(i32* %P) {
; CHECK-LABEL: define {{[^@]+}}@fn2
; CHECK-SAME: (i32* [[P:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[IF_END:%.*]]
; CHECK: for.cond1:
; CHECK-NEXT: br i1 false, label [[IF_END]], label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn1(i32 undef)
; CHECK-NEXT: store i32 [[CALL]], i32* [[P]]
; CHECK-NEXT: br label [[FOR_COND1:%.*]]
;
entry:
br label %if.end
@ -13,17 +25,36 @@ if.end: ; preds = %lbl, %for.cond1
%e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ], [ null, %for.cond1 ]
%0 = load i32, i32* %e.2, align 4
%call = call i32 @fn1(i32 %0)
store i32 %call, i32* %P
br label %for.cond1
}
define internal i32 @fn1(i32 %p1) {
; CHECK-LABEL: define {{[^@]+}}@fn1
; CHECK-SAME: (i32 [[P1:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[COND:%.*]] = select i1 undef, i32 undef, i32 undef
; CHECK-NEXT: ret i32 [[COND]]
;
entry:
%tobool = icmp ne i32 %p1, 0
%cond = select i1 %tobool, i32 %p1, i32 %p1
ret i32 %cond
}
define void @fn_no_null_opt() #0 {
define void @fn_no_null_opt(i32* %P) #0 {
; CHECK-LABEL: define {{[^@]+}}@fn_no_null_opt
; CHECK-SAME: (i32* [[P:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[IF_END:%.*]]
; CHECK: for.cond1:
; CHECK-NEXT: br i1 false, label [[IF_END]], label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* null, align 4
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn0(i32 [[TMP0]])
; CHECK-NEXT: store i32 [[CALL]], i32* [[P]]
; CHECK-NEXT: br label [[FOR_COND1:%.*]]
;
entry:
br label %if.end
@ -34,10 +65,18 @@ if.end: ; preds = %lbl, %for.cond1
%e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ], [ null, %for.cond1 ]
%0 = load i32, i32* %e.2, align 4
%call = call i32 @fn0(i32 %0)
store i32 %call, i32* %P
br label %for.cond1
}
define internal i32 @fn0(i32 %p1) {
; CHECK-LABEL: define {{[^@]+}}@fn0
; CHECK-SAME: (i32 [[P1:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[P1]], 0
; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[P1]], i32 [[P1]]
; CHECK-NEXT: ret i32 [[COND]]
;
entry:
%tobool = icmp ne i32 %p1, 0
%cond = select i1 %tobool, i32 %p1, i32 %p1
@ -45,18 +84,3 @@ entry:
}
attributes #0 = { "null-pointer-is-valid"="true" }
; CHECK-LABEL: define void @fn2(
; CHECK: call i32 @fn1(i32 undef)
; CHECK-LABEL: define internal i32 @fn1(
; CHECK:%[[COND:.*]] = select i1 undef, i32 undef, i32 undef
; CHECK: ret i32 %[[COND]]
; CHECK-LABEL: define void @fn_no_null_opt(
; CHECK: call i32 @fn0(i32 %0)
; CHECK-LABEL: define internal i32 @fn0(
; CHECK:%[[TOBOOL:.*]] = icmp ne i32 %p1, 0
; CHECK:%[[COND:.*]] = select i1 %[[TOBOOL]], i32 %p1, i32 %p1
; CHECK: ret i32 %[[COND]]

View File

@ -1,6 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -ipconstprop | FileCheck %s --check-prefixes=ALL,IPCP
; RUN: opt -S -passes=attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=1 < %s | FileCheck %s --check-prefixes=ALL,ATTRIBUTOR
; RUN: opt < %s -S -ipconstprop | FileCheck %s
%struct.wobble = type { i32 }
%struct.zot = type { %struct.wobble, %struct.wobble, %struct.wobble }
@ -8,25 +7,20 @@
declare dso_local fastcc float @bar(%struct.wobble* noalias, <8 x i32>) unnamed_addr
define %struct.zot @widget(<8 x i32> %arg) local_unnamed_addr {
; ALL-LABEL: @widget(
; ALL-NEXT: bb:
; ALL-NEXT: ret [[STRUCT_ZOT:%.*]] undef
; CHECK-LABEL: @widget(
; CHECK-NEXT: bb:
; CHECK-NEXT: ret [[STRUCT_ZOT:%.*]] undef
;
bb:
ret %struct.zot undef
}
define void @baz(<8 x i32> %arg) local_unnamed_addr {
; IPCP-LABEL: @baz(
; IPCP-NEXT: bb:
; IPCP-NEXT: [[TMP:%.*]] = call [[STRUCT_ZOT:%.*]] @widget(<8 x i32> [[ARG:%.*]])
; IPCP-NEXT: [[TMP1:%.*]] = extractvalue [[STRUCT_ZOT]] %tmp, 0, 0
; IPCP-NEXT: ret void
;
; ATTRIBUTOR-LABEL: @baz(
; ATTRIBUTOR-NEXT: bb:
; ATTRIBUTOR-NEXT: [[TMP1:%.*]] = extractvalue [[STRUCT_ZOT:%.*]] undef, 0, 0
; ATTRIBUTOR-NEXT: ret void
; CHECK-LABEL: @baz(
; CHECK-NEXT: bb:
; CHECK-NEXT: [[TMP:%.*]] = call [[STRUCT_ZOT:%.*]] @widget(<8 x i32> [[ARG:%.*]])
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue [[STRUCT_ZOT]] %tmp, 0, 0
; CHECK-NEXT: ret void
;
bb:
%tmp = call %struct.zot @widget(<8 x i32> %arg)

View File

@ -50,10 +50,11 @@ define internal i16 @bar(i16 %p1, i16 %p2) {
; in argument count due to varargs (as long as all non-variadic arguments have
; been provided),
define dso_local void @vararg_tests(i16 %a) {
define dso_local i16 @vararg_tests(i16 %a) {
%call1 = call i16 (i16, ...) @vararg_prop(i16 7, i16 8, i16 %a)
%call2 = call i16 bitcast (i16 (i16, i16, ...) * @vararg_no_prop to i16 (i16) *) (i16 7)
ret void
%add = add i16 %call1, %call2
ret i16 %add
}
define internal i16 @vararg_prop(i16 %p1, ...) {

View File

@ -1,4 +1,7 @@
; RUN: opt < %s -ipconstprop -deadargelim -S | not grep %X
; RUN: opt < %s -ipconstprop -deadargelim -S | FileCheck %s
; CHECK-NOT: %X
define internal i32 @foo(i32 %X) {
%Y = call i32 @foo( i32 %X ) ; <i32> [#uses=1]
%Z = add i32 %Y, 1 ; <i32> [#uses=1]

View File

@ -1,6 +1,7 @@
; RUN: opt < %s -ipconstprop -S > %t
; RUN: cat %t | grep "store i32 %Z, i32\* %Q"
; RUN: cat %t | grep "add i32 1, 3"
; RUN: opt < %s -ipconstprop -S | FileCheck %s
; CHECK: add i32 1, 3
; CHECK: store i32 %Z, i32* %Q
;; This function returns its second argument on all return statements
define internal i32* @incdec(i1 %C, i32* %V) {

View File

@ -1,4 +1,9 @@
; RUN: opt < %s -ipconstprop -instcombine -S | grep "ret i1 true" | count 2
; RUN: opt < %s -ipconstprop -instcombine -S | FileCheck %s
; CHECK: ret i1 true
; CHECK: ret i1 true
; CHECK-NOT: ret i1 true
define internal i32 @foo(i1 %C) {
br i1 %C, label %T, label %F

View File

@ -1,8 +1,9 @@
; RUN: opt < %s -ipconstprop -S > %t
; RUN: opt < %s -ipconstprop -S | FileCheck %s
;; Check that the 21 constants got propagated properly
; RUN: cat %t | grep "%M = add i32 21, 21"
; CHECK: %M = add i32 21, 21
;; Check that the second return values didn't get propagated
; RUN: cat %t | grep "%N = add i32 %B, %D"
; CHECK: %N = add i32 %B, %D
%0 = type { i32, i32 }

View File

@ -3,12 +3,15 @@
; CHECK-LABEL: @testf(
; CHECK: ret i32 undef
;
define internal i32 @testf() {
define internal i32 @testf(i1 %c) {
entry:
br i1 %c, label %if.cond, label %if.end
if.cond:
br i1 undef, label %if.then, label %if.end
if.then: ; preds = %entry, %if.then
br label %if.end
ret i32 11
if.end: ; preds = %if.then1, %entry
ret i32 10
@ -17,12 +20,12 @@ if.end: ; preds = %if.then1, %entry
; CHECK-LABEL: @test1(
; CHECK: ret i32 undef
;
define internal i32 @test1() {
define internal i32 @test1(i1 %c) {
entry:
br label %if.then
if.then: ; preds = %entry, %if.then
%call = call i32 @testf()
%call = call i32 @testf(i1 %c)
%res = icmp eq i32 %call, 10
br i1 %res, label %ret1, label %ret2
@ -34,10 +37,10 @@ ret2: ; preds = %if.then, %entry
}
; CHECK-LABEL: @main(
; CHECK-NEXT: %res = call i32 @test1()
; CHECK-NEXT: %res = call i32 @test1(
; CHECK-NEXT: ret i32 99
;
define i32 @main() {
%res = call i32 @test1()
define i32 @main(i1 %c) {
%res = call i32 @test1(i1 %c)
ret i32 %res
}

View File

@ -1,5 +1,4 @@
; RUN: opt -ipconstprop -S < %s | FileCheck %s
; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=1 < %s | FileCheck %s
;
; #include <threads.h>
; thread_local int gtl = 0;

View File

@ -28,6 +28,3 @@ sw.default:
return:
ret i32 0
}
; CHECK: attributes #0 = { noreturn nounwind }
; CHECK: attributes #1 = { nounwind }