Add instcombine visitor for addrspacecast

llvm-svn: 194786
This commit is contained in:
Matt Arsenault 2013-11-15 05:45:08 +00:00
parent 54a2a179a1
commit a9e95abcbf
3 changed files with 36 additions and 0 deletions

View File

@ -178,6 +178,7 @@ public:
Instruction *visitPtrToInt(PtrToIntInst &CI);
Instruction *visitIntToPtr(IntToPtrInst &CI);
Instruction *visitBitCast(BitCastInst &CI);
Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI);
Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI,
Instruction *FI);
Instruction *FoldSelectIntoOp(SelectInst &SI, Value*, Value*);

View File

@ -1851,3 +1851,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
return commonPointerCastTransforms(CI);
return commonCastTransforms(CI);
}
Instruction *InstCombiner::visitAddrSpaceCast(AddrSpaceCastInst &CI) {
return commonCastTransforms(CI);
}

View File

@ -0,0 +1,31 @@
; RUN: opt -instcombine -S < %s | FileCheck %s
target datalayout = "e-p:64:64:64-p1:32:32:32-p2:16:16:16-n8:16:32:64"
define i32* @combine_redundant_addrspacecast(i32 addrspace(1)* %x) nounwind {
; CHECK-LABEL: @combine_redundant_addrspacecast(
; CHECK: addrspacecast i32 addrspace(1)* %x to i32*
; CHECK-NEXT: ret
%y = addrspacecast i32 addrspace(1)* %x to i32 addrspace(3)*
%z = addrspacecast i32 addrspace(3)* %y to i32*
ret i32* %z
}
define <4 x i32*> @combine_redundant_addrspacecast_vector(<4 x i32 addrspace(1)*> %x) nounwind {
; CHECK-LABEL: @combine_redundant_addrspacecast_vector(
; CHECK: addrspacecast <4 x i32 addrspace(1)*> %x to <4 x i32*>
; CHECK-NEXT: ret
%y = addrspacecast <4 x i32 addrspace(1)*> %x to <4 x i32 addrspace(3)*>
%z = addrspacecast <4 x i32 addrspace(3)*> %y to <4 x i32*>
ret <4 x i32*> %z
}
define float* @combine_redundant_addrspacecast_types(i32 addrspace(1)* %x) nounwind {
; CHECK-LABEL: @combine_redundant_addrspacecast_types(
; CHECK: addrspacecast i32 addrspace(1)* %x to float*
; CHECK-NEXT: ret
%y = addrspacecast i32 addrspace(1)* %x to i32 addrspace(3)*
%z = addrspacecast i32 addrspace(3)* %y to float*
ret float* %z
}