Skip to content

Commit ea78bfa

Browse files
committed
[FastISel] Add support for ptrtoaddr
Handle it the same as ptrtoint. For ptrtoaddr the resulting integer size is guaranteed to match the address size. For the case where address size and pointer size match, this will be a no-op. For the case where the address size is smaller than the pointer size, this will be a truncate (but this is not testable with in-tree targets).
1 parent ee19231 commit ea78bfa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,8 @@ bool FastISel::selectOperator(const User *I, unsigned Opcode) {
18431843
return selectCast(I, ISD::SINT_TO_FP);
18441844

18451845
case Instruction::IntToPtr: // Deliberate fall-through.
1846-
case Instruction::PtrToInt: {
1846+
case Instruction::PtrToInt:
1847+
case Instruction::PtrToAddr: {
18471848
EVT SrcVT = TLI.getValueType(DL, I->getOperand(0)->getType());
18481849
EVT DstVT = TLI.getValueType(DL, I->getType());
18491850
if (DstVT.bitsGT(SrcVT))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-linux-gnu -fast-isel -fast-isel-abort=1 < %s -o - | FileCheck %s
3+
4+
define i64 @ptrtoaddr(ptr %p) {
5+
; CHECK-LABEL: ptrtoaddr:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: movq %rdi, %rax
8+
; CHECK-NEXT: retq
9+
%addr = ptrtoaddr ptr %p to i64
10+
ret i64 %addr
11+
}

0 commit comments

Comments
 (0)