Skip to content

Commit c71fa50

Browse files
scottp101sys_zuul
authored and
sys_zuul
committed
MemOpt: ensure we can cast between pointers and floats
by doing ptrtoint and then a bitcast. Change-Id: If5ce7c0493f98dca6cf5d434dfe65bdf26ae6734
1 parent 5a4387d commit c71fa50

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

IGC/Compiler/CISACodeGen/MemOpt.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,6 @@ namespace {
157157
if (V->getType() == DestTy)
158158
return V;
159159

160-
if (V->getType()->isPointerTy() && DestTy->isIntegerTy())
161-
return Builder.CreatePtrToInt(V, DestTy);
162-
163-
if (V->getType()->isIntegerTy() && DestTy->isPointerTy())
164-
return Builder.CreateIntToPtr(V, DestTy);
165-
166160
if (V->getType()->isPointerTy() && DestTy->isPointerTy()) {
167161
PointerType* SrcPtrTy = cast<PointerType>(V->getType());
168162
PointerType* DstPtrTy = cast<PointerType>(DestTy);
@@ -171,6 +165,30 @@ namespace {
171165
return Builder.CreateAddrSpaceCast(V, DestTy);
172166
}
173167

168+
if (V->getType()->isPointerTy()) {
169+
if (DestTy->isIntegerTy()) {
170+
return Builder.CreatePtrToInt(V, DestTy);
171+
}
172+
else if (DestTy->isFloatingPointTy()) {
173+
uint32_t Size = DestTy->getPrimitiveSizeInBits();
174+
Value* Cast = Builder.CreatePtrToInt(
175+
V, Builder.getIntNTy(Size));
176+
return Builder.CreateBitCast(Cast, DestTy);
177+
}
178+
}
179+
180+
if (DestTy->isPointerTy()) {
181+
if (V->getType()->isIntegerTy()) {
182+
return Builder.CreateIntToPtr(V, DestTy);
183+
}
184+
else if (V->getType()->isFloatingPointTy()) {
185+
uint32_t Size = V->getType()->getPrimitiveSizeInBits();
186+
Value* Cast = Builder.CreateBitCast(
187+
V, Builder.getIntNTy(Size));
188+
return Builder.CreateIntToPtr(Cast, DestTy);
189+
}
190+
}
191+
174192
return Builder.CreateBitCast(V, DestTy);
175193
}
176194

0 commit comments

Comments
 (0)