Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 532af68

Browse files
author
Hal Finkel
committed
[InstCombine/PowerPC] Convert aligned QPX load/store intrinsics into loads/stores
InstCombine has long had logic to convert aligned Altivec load/store intrinsics into regular loads and stores. This mirrors that functionality for QPX vector load/store intrinsics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230660 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b2f521b commit 532af68

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed

lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,44 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
576576
Value *Ptr = Builder->CreateBitCast(II->getArgOperand(1), OpPtrTy);
577577
return new StoreInst(II->getArgOperand(0), Ptr, false, 1);
578578
}
579+
case Intrinsic::ppc_qpx_qvlfs:
580+
// Turn PPC QPX qvlfs -> load if the pointer is known aligned.
581+
if (getOrEnforceKnownAlignment(II->getArgOperand(0), 16, DL, AC, II, DT) >=
582+
16) {
583+
Value *Ptr = Builder->CreateBitCast(II->getArgOperand(0),
584+
PointerType::getUnqual(II->getType()));
585+
return new LoadInst(Ptr);
586+
}
587+
break;
588+
case Intrinsic::ppc_qpx_qvlfd:
589+
// Turn PPC QPX qvlfd -> load if the pointer is known aligned.
590+
if (getOrEnforceKnownAlignment(II->getArgOperand(0), 32, DL, AC, II, DT) >=
591+
32) {
592+
Value *Ptr = Builder->CreateBitCast(II->getArgOperand(0),
593+
PointerType::getUnqual(II->getType()));
594+
return new LoadInst(Ptr);
595+
}
596+
break;
597+
case Intrinsic::ppc_qpx_qvstfs:
598+
// Turn PPC QPX qvstfs -> store if the pointer is known aligned.
599+
if (getOrEnforceKnownAlignment(II->getArgOperand(1), 16, DL, AC, II, DT) >=
600+
16) {
601+
Type *OpPtrTy =
602+
PointerType::getUnqual(II->getArgOperand(0)->getType());
603+
Value *Ptr = Builder->CreateBitCast(II->getArgOperand(1), OpPtrTy);
604+
return new StoreInst(II->getArgOperand(0), Ptr);
605+
}
606+
break;
607+
case Intrinsic::ppc_qpx_qvstfd:
608+
// Turn PPC QPX qvstfd -> store if the pointer is known aligned.
609+
if (getOrEnforceKnownAlignment(II->getArgOperand(1), 32, DL, AC, II, DT) >=
610+
32) {
611+
Type *OpPtrTy =
612+
PointerType::getUnqual(II->getArgOperand(0)->getType());
613+
Value *Ptr = Builder->CreateBitCast(II->getArgOperand(1), OpPtrTy);
614+
return new StoreInst(II->getArgOperand(0), Ptr);
615+
}
616+
break;
579617
case Intrinsic::x86_sse_storeu_ps:
580618
case Intrinsic::x86_sse2_storeu_pd:
581619
case Intrinsic::x86_sse2_storeu_dq:
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
; RUN: opt -S -instcombine < %s | FileCheck %s
2+
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-f128:128:128-v128:128:128-n32:64"
3+
target triple = "powerpc64-unknown-linux-gnu"
4+
5+
declare <4 x double> @llvm.ppc.qpx.qvlfs(i8*) #1
6+
7+
define <4 x double> @test1(<4 x float>* %h) #0 {
8+
entry:
9+
%h1 = getelementptr <4 x float>* %h, i64 1
10+
%hv = bitcast <4 x float>* %h1 to i8*
11+
%vl = call <4 x double> @llvm.ppc.qpx.qvlfs(i8* %hv)
12+
13+
; CHECK-LABEL: @test1
14+
; CHECK: @llvm.ppc.qpx.qvlfs
15+
; CHECK: ret <4 x double>
16+
17+
%v0 = load <4 x float>* %h, align 8
18+
%v0e = fpext <4 x float> %v0 to <4 x double>
19+
%a = fadd <4 x double> %v0e, %vl
20+
ret <4 x double> %a
21+
}
22+
23+
define <4 x double> @test1a(<4 x float>* align 16 %h) #0 {
24+
entry:
25+
%h1 = getelementptr <4 x float>* %h, i64 1
26+
%hv = bitcast <4 x float>* %h1 to i8*
27+
%vl = call <4 x double> @llvm.ppc.qpx.qvlfs(i8* %hv)
28+
29+
; CHECK-LABEL: @test1a
30+
; CHECK-NOT: @llvm.ppc.qpx.qvlfs
31+
; CHECK: ret <4 x double>
32+
33+
%v0 = load <4 x float>* %h, align 8
34+
%v0e = fpext <4 x float> %v0 to <4 x double>
35+
%a = fadd <4 x double> %v0e, %vl
36+
ret <4 x double> %a
37+
}
38+
39+
declare void @llvm.ppc.qpx.qvstfs(<4 x double>, i8*) #0
40+
41+
define <4 x float> @test2(<4 x float>* %h, <4 x double> %d) #0 {
42+
entry:
43+
%h1 = getelementptr <4 x float>* %h, i64 1
44+
%hv = bitcast <4 x float>* %h1 to i8*
45+
call void @llvm.ppc.qpx.qvstfs(<4 x double> %d, i8* %hv)
46+
47+
%v0 = load <4 x float>* %h, align 8
48+
ret <4 x float> %v0
49+
50+
; CHECK-LABEL: @test2
51+
; CHECK: @llvm.ppc.qpx.qvstfs
52+
; CHECK: ret <4 x float>
53+
}
54+
55+
define <4 x float> @test2a(<4 x float>* align 16 %h, <4 x double> %d) #0 {
56+
entry:
57+
%h1 = getelementptr <4 x float>* %h, i64 1
58+
%hv = bitcast <4 x float>* %h1 to i8*
59+
call void @llvm.ppc.qpx.qvstfs(<4 x double> %d, i8* %hv)
60+
61+
%v0 = load <4 x float>* %h, align 8
62+
ret <4 x float> %v0
63+
64+
; CHECK-LABEL: @test2
65+
; CHECK-NOT: @llvm.ppc.qpx.qvstfs
66+
; CHECK: ret <4 x float>
67+
}
68+
69+
declare <4 x double> @llvm.ppc.qpx.qvlfd(i8*) #1
70+
71+
define <4 x double> @test1l(<4 x double>* %h) #0 {
72+
entry:
73+
%h1 = getelementptr <4 x double>* %h, i64 1
74+
%hv = bitcast <4 x double>* %h1 to i8*
75+
%vl = call <4 x double> @llvm.ppc.qpx.qvlfd(i8* %hv)
76+
77+
; CHECK-LABEL: @test1l
78+
; CHECK: @llvm.ppc.qpx.qvlfd
79+
; CHECK: ret <4 x double>
80+
81+
%v0 = load <4 x double>* %h, align 8
82+
%a = fadd <4 x double> %v0, %vl
83+
ret <4 x double> %a
84+
}
85+
86+
define <4 x double> @test1ln(<4 x double>* align 16 %h) #0 {
87+
entry:
88+
%h1 = getelementptr <4 x double>* %h, i64 1
89+
%hv = bitcast <4 x double>* %h1 to i8*
90+
%vl = call <4 x double> @llvm.ppc.qpx.qvlfd(i8* %hv)
91+
92+
; CHECK-LABEL: @test1ln
93+
; CHECK: @llvm.ppc.qpx.qvlfd
94+
; CHECK: ret <4 x double>
95+
96+
%v0 = load <4 x double>* %h, align 8
97+
%a = fadd <4 x double> %v0, %vl
98+
ret <4 x double> %a
99+
}
100+
101+
define <4 x double> @test1la(<4 x double>* align 32 %h) #0 {
102+
entry:
103+
%h1 = getelementptr <4 x double>* %h, i64 1
104+
%hv = bitcast <4 x double>* %h1 to i8*
105+
%vl = call <4 x double> @llvm.ppc.qpx.qvlfd(i8* %hv)
106+
107+
; CHECK-LABEL: @test1la
108+
; CHECK-NOT: @llvm.ppc.qpx.qvlfd
109+
; CHECK: ret <4 x double>
110+
111+
%v0 = load <4 x double>* %h, align 8
112+
%a = fadd <4 x double> %v0, %vl
113+
ret <4 x double> %a
114+
}
115+
116+
declare void @llvm.ppc.qpx.qvstfd(<4 x double>, i8*) #0
117+
118+
define <4 x double> @test2l(<4 x double>* %h, <4 x double> %d) #0 {
119+
entry:
120+
%h1 = getelementptr <4 x double>* %h, i64 1
121+
%hv = bitcast <4 x double>* %h1 to i8*
122+
call void @llvm.ppc.qpx.qvstfd(<4 x double> %d, i8* %hv)
123+
124+
%v0 = load <4 x double>* %h, align 8
125+
ret <4 x double> %v0
126+
127+
; CHECK-LABEL: @test2l
128+
; CHECK: @llvm.ppc.qpx.qvstfd
129+
; CHECK: ret <4 x double>
130+
}
131+
132+
define <4 x double> @test2ln(<4 x double>* align 16 %h, <4 x double> %d) #0 {
133+
entry:
134+
%h1 = getelementptr <4 x double>* %h, i64 1
135+
%hv = bitcast <4 x double>* %h1 to i8*
136+
call void @llvm.ppc.qpx.qvstfd(<4 x double> %d, i8* %hv)
137+
138+
%v0 = load <4 x double>* %h, align 8
139+
ret <4 x double> %v0
140+
141+
; CHECK-LABEL: @test2ln
142+
; CHECK: @llvm.ppc.qpx.qvstfd
143+
; CHECK: ret <4 x double>
144+
}
145+
146+
define <4 x double> @test2la(<4 x double>* align 32 %h, <4 x double> %d) #0 {
147+
entry:
148+
%h1 = getelementptr <4 x double>* %h, i64 1
149+
%hv = bitcast <4 x double>* %h1 to i8*
150+
call void @llvm.ppc.qpx.qvstfd(<4 x double> %d, i8* %hv)
151+
152+
%v0 = load <4 x double>* %h, align 8
153+
ret <4 x double> %v0
154+
155+
; CHECK-LABEL: @test2l
156+
; CHECK-NOT: @llvm.ppc.qpx.qvstfd
157+
; CHECK: ret <4 x double>
158+
}
159+
160+
attributes #0 = { nounwind }
161+
attributes #1 = { nounwind readonly }
162+

0 commit comments

Comments
 (0)