[llvm] ea78bfa - [FastISel] Add support for ptrtoaddr
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 07:34:23 PDT 2025
Author: Nikita Popov
Date: 2025-10-08T16:34:14+02:00
New Revision: ea78bfae78f63f0a963a9099054411db6c0eecae
URL: https://github.com/llvm/llvm-project/commit/ea78bfae78f63f0a963a9099054411db6c0eecae
DIFF: https://github.com/llvm/llvm-project/commit/ea78bfae78f63f0a963a9099054411db6c0eecae.diff
LOG: [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).
Added:
llvm/test/CodeGen/X86/ptrtoaddr-fast-isel.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index 851d445f75fa8..507b2d61a534c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1843,7 +1843,8 @@ bool FastISel::selectOperator(const User *I, unsigned Opcode) {
return selectCast(I, ISD::SINT_TO_FP);
case Instruction::IntToPtr: // Deliberate fall-through.
- case Instruction::PtrToInt: {
+ case Instruction::PtrToInt:
+ case Instruction::PtrToAddr: {
EVT SrcVT = TLI.getValueType(DL, I->getOperand(0)->getType());
EVT DstVT = TLI.getValueType(DL, I->getType());
if (DstVT.bitsGT(SrcVT))
diff --git a/llvm/test/CodeGen/X86/ptrtoaddr-fast-isel.ll b/llvm/test/CodeGen/X86/ptrtoaddr-fast-isel.ll
new file mode 100644
index 0000000000000..c302d41a42ee7
--- /dev/null
+++ b/llvm/test/CodeGen/X86/ptrtoaddr-fast-isel.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=x86_64-linux-gnu -fast-isel -fast-isel-abort=1 < %s -o - | FileCheck %s
+
+define i64 @ptrtoaddr(ptr %p) {
+; CHECK-LABEL: ptrtoaddr:
+; CHECK: # %bb.0:
+; CHECK-NEXT: movq %rdi, %rax
+; CHECK-NEXT: retq
+ %addr = ptrtoaddr ptr %p to i64
+ ret i64 %addr
+}
More information about the llvm-commits
mailing list