Imported Upstream version 5.18.0.205

Former-commit-id: 7f59f7e792705db773f1caecdaa823092f4e2927
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-11-16 08:20:38 +00:00
parent 5cd5df71cc
commit 8e12397d70
28486 changed files with 3867013 additions and 66 deletions

View File

@ -0,0 +1,23 @@
; RUN: opt -mtriple=arm64-darwin-unknown -S -consthoist < %s | FileCheck %s
%T = type { i32, i32, i32, i32 }
define i32 @test1() nounwind {
; CHECK-LABEL: test1
; CHECK: %const = bitcast i64 68141056 to i64
; CHECK: %1 = inttoptr i64 %const to %T*
; CHECK: %o1 = getelementptr %T, %T* %1, i32 0, i32 1
; CHECK: %o2 = getelementptr %T, %T* %1, i32 0, i32 2
; CHECK: %o3 = getelementptr %T, %T* %1, i32 0, i32 3
%at = inttoptr i64 68141056 to %T*
%o1 = getelementptr %T, %T* %at, i32 0, i32 1
%t1 = load i32, i32* %o1
%o2 = getelementptr %T, %T* %at, i32 0, i32 2
%t2 = load i32, i32* %o2
%a1 = add i32 %t1, %t2
%o3 = getelementptr %T, %T* %at, i32 0, i32 3
%t3 = load i32, i32* %o3
%a2 = add i32 %a1, %t3
ret i32 %a2
}

View File

@ -0,0 +1,27 @@
; RUN: opt -mtriple=arm64-darwin-unknown -S -consthoist < %s | FileCheck %s
define i128 @test1(i128 %a) nounwind {
; CHECK-LABEL: test1
; CHECK: %const = bitcast i128 12297829382473034410122878 to i128
%1 = add i128 %a, 12297829382473034410122878
%2 = add i128 %1, 12297829382473034410122878
ret i128 %2
}
; Check that we don't hoist large, but cheap constants
define i512 @test2(i512 %a) nounwind {
; CHECK-LABEL: test2
; CHECK-NOT: %const = bitcast i512 7 to i512
%1 = and i512 %a, 7
%2 = or i512 %1, 7
ret i512 %2
}
; Check that we don't hoist the shift value of a shift instruction.
define i512 @test3(i512 %a) nounwind {
; CHECK-LABEL: test3
; CHECK-NOT: %const = bitcast i512 504 to i512
%1 = shl i512 %a, 504
%2 = ashr i512 %1, 504
ret i512 %2
}

View File

@ -0,0 +1,2 @@
if not 'AArch64' in config.root.targets:
config.unsupported = True

View File

@ -0,0 +1,140 @@
; RUN: opt -consthoist -S < %s | FileCheck %s
target triple = "thumbv6m-none-eabi"
; Allocas in the entry block get handled (for free) by
; prologue/epilogue. Elsewhere they're fair game though.
define void @avoid_allocas() {
; CHECK-LABEL: @avoid_allocas
; CHECK: %addr1 = alloca i8, i32 1000
; CHECK: %addr2 = alloca i8, i32 1020
%addr1 = alloca i8, i32 1000
%addr2 = alloca i8, i32 1020
br label %elsewhere
elsewhere:
; CHECK: [[BASE:%.*]] = bitcast i32 1000 to i32
; CHECK: alloca i8, i32 [[BASE]]
; CHECK: [[NEXT:%.*]] = add i32 [[BASE]], 20
; CHECK: alloca i8, i32 [[NEXT]]
%addr3 = alloca i8, i32 1000
%addr4 = alloca i8, i32 1020
ret void
}
; The case values of switch instructions are required to be constants.
define void @avoid_switch(i32 %in) {
; CHECK-LABEL: @avoid_switch
; CHECK: switch i32 %in, label %default [
; CHECK: i32 1000, label %bb1
; CHECK: i32 1020, label %bb2
; CHECK: ]
switch i32 %in, label %default
[ i32 1000, label %bb1
i32 1020, label %bb2 ]
bb1:
ret void
bb2:
ret void
default:
ret void
}
; We don't want to convert constant divides because the benefit from converting
; them to a mul in the backend is larget than constant materialization savings.
define void @signed_const_division(i32 %in1, i32 %in2, i32* %addr) {
; CHECK-LABEL: @signed_const_division
; CHECK: %res1 = sdiv i32 %l1, 1000000000
; CHECK: %res2 = srem i32 %l2, 1000000000
entry:
br label %loop
loop:
%l1 = phi i32 [%res1, %loop], [%in1, %entry]
%l2 = phi i32 [%res2, %loop], [%in2, %entry]
%res1 = sdiv i32 %l1, 1000000000
store volatile i32 %res1, i32* %addr
%res2 = srem i32 %l2, 1000000000
store volatile i32 %res2, i32* %addr
%again = icmp eq i32 %res1, %res2
br i1 %again, label %loop, label %end
end:
ret void
}
define void @unsigned_const_division(i32 %in1, i32 %in2, i32* %addr) {
; CHECK-LABEL: @unsigned_const_division
; CHECK: %res1 = udiv i32 %l1, 1000000000
; CHECK: %res2 = urem i32 %l2, 1000000000
entry:
br label %loop
loop:
%l1 = phi i32 [%res1, %loop], [%in1, %entry]
%l2 = phi i32 [%res2, %loop], [%in2, %entry]
%res1 = udiv i32 %l1, 1000000000
store volatile i32 %res1, i32* %addr
%res2 = urem i32 %l2, 1000000000
store volatile i32 %res2, i32* %addr
%again = icmp eq i32 %res1, %res2
br i1 %again, label %loop, label %end
end:
ret void
}
;PR 28282: even when data type is larger than 64-bit, the bit width of the
;constant operand could be smaller than 64-bit. In this case, there is no
;benefit to hoist the constant.
define i32 @struct_type_test(i96 %a0, i96 %a1) {
;CHECK-LABEL: @struct_type_test
entry:
;CHECK-NOT: %const = bitcast i96 32 to i96
;CHECK: lshr0 = lshr i96 %a0, 32
%lshr0 = lshr i96 %a0, 32
%cast0 = trunc i96 %lshr0 to i32
;CHECK: lshr1 = lshr i96 %a1, 32
%lshr1 = lshr i96 %a1, 32
%cast1 = trunc i96 %lshr1 to i32
%ret = add i32 %cast0, %cast1
ret i32 %ret
}
@exception_type = external global i8
; Constants in inline ASM should not be hoisted.
define i32 @inline_asm_invoke() personality i8* null {
;CHECK-LABEL: @inline_asm_invoke
;CHECK-NOT: %const = 214672
;CHECK: %X = invoke i32 asm "bswap $0", "=r,r"(i32 214672)
%X = invoke i32 asm "bswap $0", "=r,r"(i32 214672)
to label %L unwind label %lpad
;CHECK: %Y = invoke i32 asm "bswap $0", "=r,r"(i32 214672)
%Y = invoke i32 asm "bswap $0", "=r,r"(i32 214672)
to label %L unwind label %lpad
L:
ret i32 %X
lpad:
%lp = landingpad i32
cleanup
catch i8* @exception_type
ret i32 1
}
define i32 @inline_asm_call() {
;CHECK-LABEL: @inline_asm_call
;CHECK-NOT: %const = 214672
;CHECK: %X = call i32 asm "bswap $0", "=r,r"(i32 214672)
%X = call i32 asm "bswap $0", "=r,r"(i32 214672)
;CHECK: %Y = call i32 asm "bswap $0", "=r,r"(i32 214672)
%Y = call i32 asm "bswap $0", "=r,r"(i32 214672)
ret i32 %X
}

View File

@ -0,0 +1,42 @@
; RUN: opt -mtriple=arm-arm-none-eabi -consthoist -S < %s | FileCheck %s
; There are different candidates here for the base constant: 1073876992 and
; 1073876996. But we don't want to see the latter because it results in
; negative offsets.
define void @foo() #0 {
entry:
; CHECK-LABEL: @foo
; CHECK-NOT: [[CONST1:%const_mat[0-9]*]] = add i32 %const, -4
%0 = load volatile i32, i32* inttoptr (i32 1073876992 to i32*), align 4096
%or = or i32 %0, 1
store volatile i32 %or, i32* inttoptr (i32 1073876992 to i32*), align 4096
%1 = load volatile i32, i32* inttoptr (i32 1073876996 to i32*), align 4
%and = and i32 %1, -117506048
store volatile i32 %and, i32* inttoptr (i32 1073876996 to i32*), align 4
%2 = load volatile i32, i32* inttoptr (i32 1073876992 to i32*), align 4096
%and1 = and i32 %2, -17367041
store volatile i32 %and1, i32* inttoptr (i32 1073876996 to i32*), align 4096
%3 = load volatile i32, i32* inttoptr (i32 1073876992 to i32*), align 4096
%and2 = and i32 %3, -262145
store volatile i32 %and2, i32* inttoptr (i32 1073876992 to i32*), align 4096
%4 = load volatile i32, i32* inttoptr (i32 1073876996 to i32*), align 4
%and3 = and i32 %4, -8323073
store volatile i32 %and3, i32* inttoptr (i32 1073876996 to i32*), align 4
store volatile i32 10420224, i32* inttoptr (i32 1073877000 to i32*), align 8
%5 = load volatile i32, i32* inttoptr (i32 1073876996 to i32*), align 4096
%or4 = or i32 %5, 65536
store volatile i32 %or4, i32* inttoptr (i32 1073876996 to i32*), align 4096
%6 = load volatile i32, i32* inttoptr (i32 1073881088 to i32*), align 8192
%or6.i.i = or i32 %6, 16
store volatile i32 %or6.i.i, i32* inttoptr (i32 1073881088 to i32*), align 8192
%7 = load volatile i32, i32* inttoptr (i32 1073881088 to i32*), align 8192
%and7.i.i = and i32 %7, -4
store volatile i32 %and7.i.i, i32* inttoptr (i32 1073881088 to i32*), align 8192
%8 = load volatile i32, i32* inttoptr (i32 1073881088 to i32*), align 8192
%or8.i.i = or i32 %8, 2
store volatile i32 %or8.i.i, i32* inttoptr (i32 1073881088 to i32*), align 8192
ret void
}
attributes #0 = { minsize norecurse nounwind optsize readnone uwtable }

View File

@ -0,0 +1,37 @@
; RUN: opt -consthoist -S < %s | FileCheck %s
target triple = "thumbv6m-none-eabi"
%T = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32 }
; Indices for GEPs that index into a struct type should not be hoisted.
define i32 @test1(%T* %P) nounwind {
; CHECK-LABEL: @test1
; CHECK: %const = bitcast i32 256 to i32
; CHECK: %addr1 = getelementptr %T, %T* %P, i32 %const, i32 256
; CHECK: %addr2 = getelementptr %T, %T* %P, i32 %const, i32 256
; The first index into the pointer is hoisted, but the second one into the
; struct isn't.
%addr1 = getelementptr %T, %T* %P, i32 256, i32 256
%tmp1 = load i32, i32* %addr1
%addr2 = getelementptr %T, %T* %P, i32 256, i32 256
%tmp2 = load i32, i32* %addr2
%tmp4 = add i32 %tmp1, %tmp2
ret i32 %tmp4
}

View File

@ -0,0 +1,31 @@
; RUN: opt -consthoist -S < %s | FileCheck %s
target triple = "thumbv6m-none-eabi"
%T = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32, i32 }
; The second operand of insertvalue is able to be hoisted.
define void @test1(%T %P) {
; CHECK-LABEL: @test1
; CHECK: %const = bitcast i32 256 to i32
; CHECK: %1 = insertvalue %T %P, i32 %const, 256
; CHECK: %2 = insertvalue %T %P, i32 %const, 256
%1 = insertvalue %T %P, i32 256, 256
%2 = insertvalue %T %P, i32 256, 256
ret void
}

View File

@ -0,0 +1,2 @@
if not 'ARM' in config.root.targets:
config.unsupported = True

View File

@ -0,0 +1,23 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "E-m:e-i64:64-n32:64"
target triple = "powerpc64-unknown-linux-gnu"
%T = type { i32, i32, i32, i32 }
; Test if even cheap base addresses are hoisted.
define i32 @test1() nounwind {
; CHECK-LABEL: @test1
; CHECK: %const = bitcast i32 12345678 to i32
; CHECK: %1 = inttoptr i32 %const to %T*
; CHECK: %addr1 = getelementptr %T, %T* %1, i32 0, i32 1
%addr1 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 1
%tmp1 = load i32, i32* %addr1
%addr2 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 2
%tmp2 = load i32, i32* %addr2
%addr3 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 3
%tmp3 = load i32, i32* %addr3
%tmp4 = add i32 %tmp1, %tmp2
%tmp5 = add i32 %tmp3, %tmp4
ret i32 %tmp5
}

View File

@ -0,0 +1,3 @@
if not 'PowerPC' in config.root.targets:
config.unsupported = True

View File

@ -0,0 +1,66 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "E-m:e-i64:64-n32:64"
target triple = "powerpc64-unknown-linux-gnu"
; Here the masks are all contiguous, and should not be hoisted.
define i32 @test1() nounwind {
entry:
; CHECK-LABEL: @test1
; CHECK-NOT: bitcast i32 65535 to i32
; CHECK: and i32 undef, 65535
%conv121 = and i32 undef, 65535
br i1 undef, label %if.then152, label %if.end167
if.then152:
; CHECK: and i32 undef, 65535
%conv153 = and i32 undef, 65535
br i1 undef, label %if.end167, label %end2
if.end167:
; CHECK: and i32 {{.*}}, 32768
%shl161 = shl nuw nsw i32 %conv121, 15
%0 = load i8, i8* undef, align 1
%conv169 = zext i8 %0 to i32
%shl170 = shl nuw nsw i32 %conv169, 7
%shl161.masked = and i32 %shl161, 32768
%conv174 = or i32 %shl170, %shl161.masked
%cmp178 = icmp ugt i32 %conv174, 32767
br i1 %cmp178, label %end1, label %end2
end1:
unreachable
end2:
unreachable
}
; Here the masks are not contiguous, and should be hoisted.
define i32 @test2() nounwind {
entry:
; CHECK-LABEL: @test2
; CHECK: bitcast i32 65531 to i32
%conv121 = and i32 undef, 65531
br i1 undef, label %if.then152, label %if.end167
if.then152:
%conv153 = and i32 undef, 65531
br i1 undef, label %if.end167, label %end2
if.end167:
; CHECK: add i32 {{.*}}, -32758
%shl161 = shl nuw nsw i32 %conv121, 15
%0 = load i8, i8* undef, align 1
%conv169 = zext i8 %0 to i32
%shl170 = shl nuw nsw i32 %conv169, 7
%shl161.masked = and i32 %shl161, 32773
%conv174 = or i32 %shl170, %shl161.masked
%cmp178 = icmp ugt i32 %conv174, 32767
br i1 %cmp178, label %end1, label %end2
end1:
unreachable
end2:
unreachable
}

View File

@ -0,0 +1,30 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
; RUN: opt -S -passes='consthoist' < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"
; Check if the materialization of the constant and the cast instruction are
; inserted in the correct order.
define i32 @cast_inst_test() {
; CHECK-LABEL: @cast_inst_test
; CHECK: %const = bitcast i64 4646526064 to i64
; CHECK: %1 = inttoptr i64 %const to i32*
; CHECK: %v0 = load i32, i32* %1, align 16
; CHECK: %const_mat = add i64 %const, 16
; CHECK-NEXT: %2 = inttoptr i64 %const_mat to i32*
; CHECK-NEXT: %v1 = load i32, i32* %2, align 16
; CHECK: %const_mat1 = add i64 %const, 32
; CHECK-NEXT: %3 = inttoptr i64 %const_mat1 to i32*
; CHECK-NEXT: %v2 = load i32, i32* %3, align 16
%a0 = inttoptr i64 4646526064 to i32*
%v0 = load i32, i32* %a0, align 16
%a1 = inttoptr i64 4646526080 to i32*
%v1 = load i32, i32* %a1, align 16
%a2 = inttoptr i64 4646526096 to i32*
%v2 = load i32, i32* %a2, align 16
%r0 = add i32 %v0, %v1
%r1 = add i32 %r0, %v2
ret i32 %r1
}

View File

@ -0,0 +1,24 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"
%T = type { i32, i32, i32, i32 }
; Test if even cheap base addresses are hoisted.
define i32 @test1() nounwind {
; CHECK-LABEL: @test1
; CHECK: %const = bitcast i32 12345678 to i32
; CHECK: %1 = inttoptr i32 %const to %T*
; CHECK: %addr1 = getelementptr %T, %T* %1, i32 0, i32 1
%addr1 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 1
%tmp1 = load i32, i32* %addr1
%addr2 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 2
%tmp2 = load i32, i32* %addr2
%addr3 = getelementptr %T, %T* inttoptr (i32 12345678 to %T*), i32 0, i32 3
%tmp3 = load i32, i32* %addr3
%tmp4 = add i32 %tmp1, %tmp2
%tmp5 = add i32 %tmp3, %tmp4
ret i32 %tmp5
}

View File

@ -0,0 +1,55 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
; ModuleID = 'test-hoist-debug.cpp'
source_filename = "test-hoist-debug.cpp"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone uwtable
define i32 @_Z3foov() !dbg !7 {
; CHECK: bitcast
; CHECK-NOT: !dbg !11
; CHECK: inttoptr
entry:
%a0 = inttoptr i64 4646526064 to i32*
%v0 = load i32, i32* %a0, align 16, !dbg !11
%c = alloca i32, align 4
store i32 1, i32* %c, align 4
%0 = load i32, i32* %c, align 4
%cmp = icmp eq i32 %0, 0
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
%a1 = inttoptr i64 4646526080 to i32*
%v1 = load i32, i32* %a1, align 16, !dbg !11
br label %return
if.else: ; preds = %entry
%a2 = inttoptr i64 4646526096 to i32*
%v2 = load i32, i32* %a2, align 16, !dbg !11
br label %return
return: ; preds = %if.else, %if.then
%vx = phi i32 [%v1, %if.then], [%v2, %if.else]
%r0 = add i32 %vx, %v0
ret i32 %r0
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 313291)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "test-hoist-debug.cpp", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 6.0.0 (trunk 313291)"}
!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, column: 3, scope: !7)
!12 = !DILocation(line: 3, column: 3, scope: !7)
!13 = !DILocation(line: 4, column: 3, scope: !7)

View File

@ -0,0 +1,41 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
; ModuleID = 'test-hoist-debug.cpp'
source_filename = "test-hoist-debug.cpp"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone uwtable
define i32 @_Z3foov() !dbg !7 {
; CHECK: bitcast
; CHECK: !dbg !11
; CHECK: inttoptr
%a0 = inttoptr i64 4646526064 to i32*, !dbg !11
%v0 = load i32, i32* %a0, align 16, !dbg !11
%a1 = inttoptr i64 4646526080 to i32*
%v1 = load i32, i32* %a1, align 16, !dbg !11
%a2 = inttoptr i64 4646526096 to i32*
%v2 = load i32, i32* %a2, align 16, !dbg !11
%r0 = add i32 %v0, %v1
%r1 = add i32 %r0, %v2
ret i32 %r1
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 313291)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "test-hoist-debug.cpp", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 6.0.0 (trunk 313291)"}
!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, column: 3, scope: !7)

View File

@ -0,0 +1,22 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"
%T = type { i32, i32, i32, i32 }
define i32 @test1() nounwind {
; CHECK-LABEL: @test1
; CHECK: %const = bitcast i32 12345678 to i32
; CHECK-NOT: %base = inttoptr i32 12345678 to %T*
; CHECK-NEXT: %1 = inttoptr i32 %const to %T*
; CHECK-NEXT: %addr1 = getelementptr %T, %T* %1, i32 0, i32 1
; CHECK-NEXT: %addr2 = getelementptr %T, %T* %1, i32 0, i32 2
; CHECK-NEXT: %addr3 = getelementptr %T, %T* %1, i32 0, i32 3
%base = inttoptr i32 12345678 to %T*
%addr1 = getelementptr %T, %T* %base, i32 0, i32 1
%addr2 = getelementptr %T, %T* %base, i32 0, i32 2
%addr3 = getelementptr %T, %T* %base, i32 0, i32 3
ret i32 12345678
}

View File

@ -0,0 +1,70 @@
; RUN: opt -S -consthoist -consthoist-with-block-frequency=false < %s | FileCheck %s
; RUN: opt -S -consthoist -consthoist-with-block-frequency=true < %s | FileCheck --check-prefix=BFIHOIST %s
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
; CHECK-LABEL: define i32 @main
; CHECK: %tobool = icmp eq i32 %argc, 0
; CHECK-NEXT: bitcast i64 9209618997431186100 to i64
; CHECK-NEXT: br i1 %tobool
; BFIHOIST-LABEL: define i32 @main
; BFIHOIST: then:
; BFIHOIST: %[[CONST1:.*]] = bitcast i64 9209618997431186100 to i64
; BFIHOIST: %add = add i64 %call4, %[[CONST1]]
; BFIHOIST: br label %endif
; BFIHOIST: else:
; BFIHOIST: %[[CONST2:.*]] = bitcast i64 9209618997431186100 to i64
; BFIHOIST: %add6 = add i64 %call5, %[[CONST2]]
; BFIHOIST: br label %endif
; Function Attrs: norecurse
define i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
%call = tail call i64 @fn(i64 0)
%call1 = tail call i64 @fn(i64 1)
%tobool = icmp eq i32 %argc, 0
br i1 %tobool, label %2, label %1
; <label>:1: ; preds = %0
%call2 = invoke i64 @fn(i64 %call)
to label %6 unwind label %catch.dispatch
; <label>:2: ; preds = %0
%call3 = invoke i64 @fn(i64 %call1)
to label %6 unwind label %catch.dispatch
catch.dispatch: ; preds = %2, %1
%z.0 = phi i64 [ %call, %1 ], [ %call1, %2 ]
%3 = catchswitch within none [label %4] unwind to caller
; <label>:4: ; preds = %catch.dispatch
%5 = catchpad within %3 [i8* null, i32 64, i8* null]
br i1 %tobool, label %then, label %else
then:
%call4 = tail call i64 @fn(i64 %z.0) [ "funclet"(token %5) ]
%add = add i64 %call4, 9209618997431186100
br label %endif
else:
%call5 = tail call i64 @fn(i64 0) [ "funclet"(token %5) ]
%add6 = add i64 %call5, 9209618997431186100
br label %endif
endif:
%v = phi i64 [ %add, %then ], [ %add6, %else ]
%call7 = tail call i64 @fn(i64 %v) [ "funclet"(token %5) ]
%call8 = tail call i64 @fn(i64 %call7) [ "funclet"(token %5) ]
catchret from %5 to label %6
; <label>:6: ; preds = %1, %2, %4
ret i32 0
}
declare i64 @fn(i64) local_unnamed_addr #1
declare i32 @__CxxFrameHandler3(...)
attributes #0 = { norecurse "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }

View File

@ -0,0 +1,36 @@
; RUN: opt -mtriple=x86_64-darwin-unknown -S -consthoist < %s | FileCheck %s
define i128 @test1(i128 %a) nounwind {
; CHECK-LABEL: test1
; CHECK: %const = bitcast i128 12297829382473034410122878 to i128
%1 = add i128 %a, 12297829382473034410122878
%2 = add i128 %1, 12297829382473034410122878
ret i128 %2
}
; Check that we don't hoist the shift value of a shift instruction.
define i512 @test2(i512 %a) nounwind {
; CHECK-LABEL: test2
; CHECK-NOT: %const = bitcast i512 504 to i512
%1 = shl i512 %a, 504
%2 = ashr i512 %1, 504
ret i512 %2
}
; Check that we don't hoist constants with a type larger than i128.
define i196 @test3(i196 %a) nounwind {
; CHECK-LABEL: test3
; CHECK-NOT: %const = bitcast i196 2 to i196
%1 = mul i196 %a, 2
%2 = mul i196 %1, 2
ret i196 %2
}
; Check that we don't hoist immediates with small values.
define i96 @test4(i96 %a) nounwind {
; CHECK-LABEL: test4
; CHECK-NOT: %const = bitcast i96 2 to i96
%1 = mul i96 %a, 2
%2 = add i96 %1, 2
ret i96 %2
}

View File

@ -0,0 +1,3 @@
if not 'X86' in config.root.targets:
config.unsupported = True

View File

@ -0,0 +1,116 @@
; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"
; PR18626
define i8* @test1(i1 %cmp, i64* %tmp) {
entry:
call void @foo(i8* inttoptr (i64 68719476735 to i8*))
br i1 %cmp, label %if.end, label %return
if.end: ; preds = %bb1
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br label %return
return:
%retval.0 = phi i8* [ null, %entry ], [ inttoptr (i64 68719476736 to i8*), %if.end ]
store i64 1172321806, i64* %tmp
ret i8* %retval.0
; CHECK-LABEL: @test1
; CHECK: if.end:
; CHECK: %2 = inttoptr i64 %const to i8*
; CHECK-NEXT: br
; CHECK: return:
; CHECK-NEXT: %retval.0 = phi i8* [ null, %entry ], [ %2, %if.end ]
}
define void @test2(i1 %cmp, i64** %tmp) {
entry:
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br i1 %cmp, label %if.end, label %return
if.end: ; preds = %bb1
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br label %return
return:
store i64* inttoptr (i64 68719476735 to i64*), i64** %tmp
ret void
; CHECK-LABEL: @test2
; CHECK: return:
; CHECK-NEXT: %const_mat = add i64 %const, -1
; CHECK-NEXT: inttoptr i64 %const_mat to i64*
}
declare void @foo(i8*)
; PR18768
define i32 @test3(i1 %c) {
entry:
br i1 %c, label %if.then, label %if.end3
if.then: ; preds = %entry
br label %if.end3
if.end3: ; preds = %if.then, %entry
%d.0 = phi i32* [ inttoptr (i64 985162435264511 to i32*), %entry ], [ null, %if.then ]
%cmp4 = icmp eq i32* %d.0, inttoptr (i64 985162435264511 to i32*)
%cmp6 = icmp eq i32* %d.0, inttoptr (i64 985162418487296 to i32*)
%or = or i1 %cmp4, %cmp6
br i1 %or, label %if.then8, label %if.end9
if.then8: ; preds = %if.end3
ret i32 1
if.end9: ; preds = %if.then8, %if.end3
ret i32 undef
}
; <rdar://problem/16394449>
define i64 @switch_test1(i64 %a) {
; CHECK-LABEL: @switch_test1
; CHECK: %0 = phi i64 [ %const, %case2 ], [ %const_mat, %Entry ], [ %const_mat, %Entry ]
Entry:
%sel = add i64 %a, 4519019440
switch i64 %sel, label %fail [
i64 462, label %continuation
i64 449, label %case2
i64 443, label %continuation
]
case2:
br label %continuation
continuation:
%0 = phi i64 [ 4519019440, %case2 ], [ 4519019460, %Entry ], [ 4519019460, %Entry ]
ret i64 0;
fail:
ret i64 -1;
}
define i64 @switch_test2(i64 %a) {
; CHECK-LABEL: @switch_test2
; CHECK: %2 = phi i64* [ %1, %case2 ], [ %0, %Entry ], [ %0, %Entry ]
Entry:
%sel = add i64 %a, 4519019440
switch i64 %sel, label %fail [
i64 462, label %continuation
i64 449, label %case2
i64 443, label %continuation
]
case2:
br label %continuation
continuation:
%0 = phi i64* [ inttoptr(i64 4519019440 to i64*), %case2 ], [ inttoptr(i64 4519019460 to i64*), %Entry ], [ inttoptr(i64 4519019460 to i64*), %Entry ]
ret i64 0;
fail:
ret i64 -1;
}

Some files were not shown because too many files have changed in this diff Show More