2015-03-15 06:19:33 +08:00
|
|
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
|
|
|
|
|
|
|
target datalayout = "e-i64:64-f80:128-n8:16:32:64"
|
|
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
|
|
|
|
%A__vtbl = type { i8*, i32 (%A*)* }
|
|
|
|
%A = type { %A__vtbl* }
|
2015-12-15 09:44:07 +08:00
|
|
|
%B = type { i8*, i64 }
|
2015-03-15 06:19:33 +08:00
|
|
|
|
|
|
|
@A__vtblZ = constant %A__vtbl { i8* null, i32 (%A*)* @A.foo }
|
|
|
|
|
|
|
|
declare i32 @A.foo(%A* nocapture %this)
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define void @storeA(%A* %a.ptr) {
|
2015-05-07 13:52:40 +08:00
|
|
|
; CHECK-LABEL: storeA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds %A, %A* %a.ptr, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
store %A { %A__vtbl* @A__vtblZ }, %A* %a.ptr, align 8
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @storeB(%B* %b.ptr) {
|
|
|
|
; CHECK-LABEL: storeB
|
|
|
|
; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: store i8* null, i8** [[GEP1]], align 8
|
|
|
|
; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1
|
|
|
|
; CHECK-NEXT: store i64 42, i64* [[GEP2]], align 8
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
store %B { i8* null, i64 42 }, %B* %b.ptr, align 8
|
2015-03-15 06:19:33 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define void @storeStructOfA({ %A }* %sa.ptr) {
|
2015-05-07 13:52:40 +08:00
|
|
|
; CHECK-LABEL: storeStructOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0
|
|
|
|
; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
store { %A } { %A { %A__vtbl* @A__vtblZ } }, { %A }* %sa.ptr, align 8
|
2015-03-15 06:19:33 +08:00
|
|
|
ret void
|
|
|
|
}
|
2015-05-07 13:52:40 +08:00
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define void @storeArrayOfA([1 x %A]* %aa.ptr) {
|
2015-05-11 13:33:27 +08:00
|
|
|
; CHECK-LABEL: storeArrayOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds [1 x %A], [1 x %A]* %aa.ptr, i64 0, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
store [1 x %A] [%A { %A__vtbl* @A__vtblZ }], [1 x %A]* %aa.ptr, align 8
|
2015-05-11 13:04:27 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define void @storeStructOfArrayOfA({ [1 x %A] }* %saa.ptr) {
|
2015-05-11 13:04:27 +08:00
|
|
|
; CHECK-LABEL: storeStructOfArrayOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { [1 x %A] }, { [1 x %A] }* %saa.ptr, i64 0, i32 0, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
store { [1 x %A] } { [1 x %A] [%A { %A__vtbl* @A__vtblZ }] }, { [1 x %A] }* %saa.ptr, align 8
|
2015-05-11 13:04:27 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define %A @loadA(%A* %a.ptr) {
|
2015-05-07 13:52:40 +08:00
|
|
|
; CHECK-LABEL: loadA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds %A, %A* %a.ptr, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: [[IV:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0
|
|
|
|
; CHECK-NEXT: ret %A [[IV]]
|
|
|
|
%1 = load %A, %A* %a.ptr, align 8
|
|
|
|
ret %A %1
|
2015-05-07 13:52:40 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define %B @loadB(%B* %b.ptr) {
|
|
|
|
; CHECK-LABEL: loadB
|
|
|
|
; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: [[LOAD1:%[a-z0-9\.]+]] = load i8*, i8** [[GEP1]], align 8
|
|
|
|
; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %B undef, i8* [[LOAD1]], 0
|
|
|
|
; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1
|
|
|
|
; CHECK-NEXT: [[LOAD2:%[a-z0-9\.]+]] = load i64, i64* [[GEP2]], align 8
|
|
|
|
; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue %B [[IV1]], i64 [[LOAD2]], 1
|
|
|
|
; CHECK-NEXT: ret %B [[IV2]]
|
|
|
|
%1 = load %B, %B* %b.ptr, align 8
|
|
|
|
ret %B %1
|
|
|
|
}
|
|
|
|
|
|
|
|
define { %A } @loadStructOfA({ %A }* %sa.ptr) {
|
2015-05-07 13:52:40 +08:00
|
|
|
; CHECK-LABEL: loadStructOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0
|
|
|
|
; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0
|
|
|
|
; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue { %A } undef, %A [[IV1]], 0
|
|
|
|
; CHECK-NEXT: ret { %A } [[IV2]]
|
|
|
|
%1 = load { %A }, { %A }* %sa.ptr, align 8
|
|
|
|
ret { %A } %1
|
2015-05-07 13:52:40 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define [1 x %A] @loadArrayOfA([1 x %A]* %aa.ptr) {
|
2015-05-11 13:04:22 +08:00
|
|
|
; CHECK-LABEL: loadArrayOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds [1 x %A], [1 x %A]* %aa.ptr, i64 0, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0
|
|
|
|
; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue [1 x %A] undef, %A [[IV1]], 0
|
|
|
|
; CHECK-NEXT: ret [1 x %A] [[IV2]]
|
|
|
|
%1 = load [1 x %A], [1 x %A]* %aa.ptr, align 8
|
|
|
|
ret [1 x %A] %1
|
2015-05-11 13:04:22 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define { [1 x %A] } @loadStructOfArrayOfA({ [1 x %A] }* %saa.ptr) {
|
2015-05-11 13:04:22 +08:00
|
|
|
; CHECK-LABEL: loadStructOfArrayOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { [1 x %A] }, { [1 x %A] }* %saa.ptr, i64 0, i32 0, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0
|
|
|
|
; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue [1 x %A] undef, %A [[IV1]], 0
|
|
|
|
; CHECK-NEXT: [[IV3:%[a-z0-9\.]+]] = insertvalue { [1 x %A] } undef, [1 x %A] [[IV2]], 0
|
|
|
|
; CHECK-NEXT: ret { [1 x %A] } [[IV3]]
|
|
|
|
%1 = load { [1 x %A] }, { [1 x %A] }* %saa.ptr, align 8
|
|
|
|
ret { [1 x %A] } %1
|
2015-05-11 13:04:22 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:44:07 +08:00
|
|
|
define { %A } @structOfA({ %A }* %sa.ptr) {
|
2015-05-07 13:52:40 +08:00
|
|
|
; CHECK-LABEL: structOfA
|
2015-12-15 09:44:07 +08:00
|
|
|
; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0
|
|
|
|
; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8
|
|
|
|
; CHECK-NEXT: ret { %A } { %A { %A__vtbl* @A__vtblZ } }
|
|
|
|
store { %A } { %A { %A__vtbl* @A__vtblZ } }, { %A }* %sa.ptr, align 8
|
|
|
|
%1 = load { %A }, { %A }* %sa.ptr, align 8
|
|
|
|
ret { %A } %1
|
|
|
|
}
|
|
|
|
|
|
|
|
define %B @structB(%B* %b.ptr) {
|
|
|
|
; CHECK-LABEL: structB
|
|
|
|
; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0
|
|
|
|
; CHECK-NEXT: store i8* null, i8** [[GEP1]], align 8
|
|
|
|
; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1
|
|
|
|
; CHECK-NEXT: store i64 42, i64* [[GEP2]], align 8
|
|
|
|
; CHECK-NEXT: ret %B { i8* null, i64 42 }
|
|
|
|
store %B { i8* null, i64 42 }, %B* %b.ptr, align 8
|
|
|
|
%1 = load %B, %B* %b.ptr, align 8
|
|
|
|
ret %B %1
|
2015-05-07 13:52:40 +08:00
|
|
|
}
|