1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[InstCombine] Don't try converting opaque pointer bitcast to GEP

Bitcasts having opaque pointer source or result type cannot be
converted into a zero-index GEP, GEP source and result types
always have the same opaque-ness.
This commit is contained in:
Nikita Popov 2021-06-21 20:35:30 +02:00
parent 3ff4077a87
commit 2b34d4059b
2 changed files with 48 additions and 0 deletions

View File

@ -2608,6 +2608,11 @@ static Instruction *convertBitCastToGEP(BitCastInst &CI, IRBuilderBase &Builder,
Value *Src = CI.getOperand(0);
PointerType *SrcPTy = cast<PointerType>(Src->getType());
PointerType *DstPTy = cast<PointerType>(CI.getType());
// Bitcasts involving opaque pointers cannot be converted into a GEP.
if (SrcPTy->isOpaque() || DstPTy->isOpaque())
return nullptr;
Type *DstElTy = DstPTy->getElementType();
Type *SrcElTy = SrcPTy->getElementType();

View File

@ -0,0 +1,43 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instcombine < %s | FileCheck %s
define ptr @bitcast_opaque_to_opaque(ptr %a) {
; CHECK-LABEL: @bitcast_opaque_to_opaque(
; CHECK-NEXT: ret ptr [[A:%.*]]
;
%b = bitcast ptr %a to ptr
ret ptr %b
}
define ptr @bitcast_typed_to_opaque(i8* %a) {
; CHECK-LABEL: @bitcast_typed_to_opaque(
; CHECK-NEXT: [[B:%.*]] = bitcast i8* [[A:%.*]] to ptr
; CHECK-NEXT: ret ptr [[B]]
;
%b = bitcast i8* %a to ptr
ret ptr %b
}
define i8* @bitcast_opaque_to_typed(ptr %a) {
; CHECK-LABEL: @bitcast_opaque_to_typed(
; CHECK-NEXT: [[B:%.*]] = bitcast ptr [[A:%.*]] to i8*
; CHECK-NEXT: ret i8* [[B]]
;
%b = bitcast ptr %a to i8*
ret i8* %b
}
;define ptr @addrspacecast_opaque_to_opaque(ptr addrspace(1) %a) {
; %b = addrspacecast ptr addrspace(1) %a to ptr
; ret ptr %b
;}
;define ptr @addrspacecast_typed_to_opaque(i8 addrspace(1)* %a) {
; %b = addrspacecast i8 addrspace(1)* %a to ptr
; ret ptr %b
;}
;define i8* @addrspacecast_opaque_to_typed(ptr addrspace(1) %a) {
; %b = addrspacecast ptr addrspace(1) %a to i8*
; ret i8* %b
;}