[llvm] Support vector `ptrtoint` and `inttoptr` with X86 GlobalISel. (PR #175270)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 22:03:38 PST 2026
https://github.com/YohayAiTe updated https://github.com/llvm/llvm-project/pull/175270
>From f146771c6763185f457ec1153276a6179ef4c3af Mon Sep 17 00:00:00 2001
From: Yohay <yohay.ailon.tevet at gmail.com>
Date: Fri, 9 Jan 2026 23:11:36 +0200
Subject: [PATCH 1/3] Added tests for vectorised inttoptr and ptrtoint on X86
GlobalISel.
---
llvm/test/CodeGen/X86/GlobalISel/inttoptr.ll | 12 --
.../CodeGen/X86/GlobalISel/inttoptr_32.ll | 112 ++++++++++++
.../CodeGen/X86/GlobalISel/inttoptr_64.ll | 115 ++++++++++++
llvm/test/CodeGen/X86/GlobalISel/ptrtoint.ll | 56 ------
.../CodeGen/X86/GlobalISel/ptrtoint_32.ll | 48 +++++
.../CodeGen/X86/GlobalISel/ptrtoint_64.ll | 166 ++++++++++++++++++
.../X86/GlobalISel/x86-legalize-ptrtoint.mir | 36 ++--
.../X86/GlobalISel/x86-select-ptrtoint.mir | 108 +-----------
.../GlobalISel/x86_64-legalize-ptrtoint.mir | 50 +++---
.../X86/GlobalISel/x86_64-select-ptrtoint.mir | 133 +-------------
10 files changed, 495 insertions(+), 341 deletions(-)
delete mode 100644 llvm/test/CodeGen/X86/GlobalISel/inttoptr.ll
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/inttoptr_32.ll
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/inttoptr_64.ll
delete mode 100644 llvm/test/CodeGen/X86/GlobalISel/ptrtoint.ll
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/ptrtoint_32.ll
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/ptrtoint_64.ll
diff --git a/llvm/test/CodeGen/X86/GlobalISel/inttoptr.ll b/llvm/test/CodeGen/X86/GlobalISel/inttoptr.ll
deleted file mode 100644
index 64daf4ea6d957..0000000000000
--- a/llvm/test/CodeGen/X86/GlobalISel/inttoptr.ll
+++ /dev/null
@@ -1,12 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=CHECK
-
-define ptr @inttoptr_p0_s64(i64 %val) {
-; CHECK-LABEL: inttoptr_p0_s64:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: retq
-entry:
- %0 = inttoptr i64 %val to ptr
- ret ptr %0
-}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/inttoptr_32.ll b/llvm/test/CodeGen/X86/GlobalISel/inttoptr_32.ll
new file mode 100644
index 0000000000000..373e87aab72e3
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/inttoptr_32.ll
@@ -0,0 +1,112 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=-sse2 -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=NO-SSE
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=+sse2 -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SSE
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=+avx -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=AVX
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=+avx512f -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=AVX512
+
+define ptr @inttoptr_p0_s32(i32 %val) {
+; CHECK-LABEL: inttoptr_p0_s32:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: movl 4(%esp), %eax
+; CHECK-NEXT: retl
+; NO-SSE-LABEL: inttoptr_p0_s32:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %eax
+; NO-SSE-NEXT: retl
+;
+; SSE-LABEL: inttoptr_p0_s32:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: movl {{[0-9]+}}(%esp), %eax
+; SSE-NEXT: retl
+;
+; AVX-LABEL: inttoptr_p0_s32:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: movl {{[0-9]+}}(%esp), %eax
+; AVX-NEXT: retl
+;
+; AVX512-LABEL: inttoptr_p0_s32:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: movl {{[0-9]+}}(%esp), %eax
+; AVX512-NEXT: retl
+entry:
+ %0 = inttoptr i32 %val to ptr
+ ret ptr %0
+}
+
+define <4 x ptr> @inttoptr_v4p0_v4s32(<4 x i32> %val) {
+; NO-SSE-LABEL: inttoptr_v4p0_v4s32:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: pushl %edi
+; NO-SSE-NEXT: .cfi_def_cfa_offset 8
+; NO-SSE-NEXT: pushl %esi
+; NO-SSE-NEXT: .cfi_def_cfa_offset 12
+; NO-SSE-NEXT: .cfi_offset %esi, -12
+; NO-SSE-NEXT: .cfi_offset %edi, -8
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %eax
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %edx
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %esi
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %edi
+; NO-SSE-NEXT: movl %ecx, (%eax)
+; NO-SSE-NEXT: movl %edx, 4(%eax)
+; NO-SSE-NEXT: movl %esi, 8(%eax)
+; NO-SSE-NEXT: movl %edi, 12(%eax)
+; NO-SSE-NEXT: popl %esi
+; NO-SSE-NEXT: .cfi_def_cfa_offset 8
+; NO-SSE-NEXT: popl %edi
+; NO-SSE-NEXT: .cfi_def_cfa_offset 4
+; NO-SSE-NEXT: retl
+;
+; SSE-LABEL: inttoptr_v4p0_v4s32:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retl
+;
+; AVX-LABEL: inttoptr_v4p0_v4s32:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retl
+;
+; AVX512-LABEL: inttoptr_v4p0_v4s32:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retl
+entry:
+ %0 = inttoptr <4 x i32> %val to <4 x ptr>
+ ret <4 x ptr> %0
+}
+
+define <8 x ptr> @inttoptr_v8p0_v8s32(<8 x i32> %val) {
+; NO-SSE-LABEL: inttoptr_v8p0_v8s32:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %eax
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, (%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 4(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 8(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 12(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 16(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 20(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 24(%eax)
+; NO-SSE-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; NO-SSE-NEXT: movl %ecx, 28(%eax)
+; NO-SSE-NEXT: retl
+;
+; SSE-LABEL: inttoptr_v8p0_v8s32:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retl
+;
+; AVX-LABEL: inttoptr_v8p0_v8s32:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retl
+;
+; AVX512-LABEL: inttoptr_v8p0_v8s32:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retl
+entry:
+ %0 = inttoptr <8 x i32> %val to <8 x ptr>
+ ret <8 x ptr> %0
+}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/inttoptr_64.ll b/llvm/test/CodeGen/X86/GlobalISel/inttoptr_64.ll
new file mode 100644
index 0000000000000..f661ee8d9776f
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/inttoptr_64.ll
@@ -0,0 +1,115 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=-sse2 -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=NO-SSE
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SSE
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=+avx -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=AVX
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=+avx512f -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=AVX512
+
+define ptr @inttoptr_p0_s64(i64 %val) {
+; NO-SSE-LABEL: inttoptr_p0_s64:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: inttoptr_p0_s64:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: movq %rdi, %rax
+; SSE-NEXT: retq
+;
+; AVX-LABEL: inttoptr_p0_s64:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: movq %rdi, %rax
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: inttoptr_p0_s64:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: movq %rdi, %rax
+; AVX512-NEXT: retq
+entry:
+ %0 = inttoptr i64 %val to ptr
+ ret ptr %0
+}
+
+define <2 x ptr> @inttoptr_v2p0_v2s64(<2 x i64> %val) {
+; CHECK-LABEL: inttoptr_v2p0_v2s64:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: retq
+; NO-SSE-LABEL: inttoptr_v2p0_v2s64:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq %rsi, %rdx
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: inttoptr_v2p0_v2s64:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: inttoptr_v2p0_v2s64:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: inttoptr_v2p0_v2s64:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = inttoptr <2 x i64> %val to <2 x ptr>
+ ret <2 x ptr> %0
+}
+
+define <4 x ptr> @inttoptr_v4p0_v4s64(<4 x i64> %val) {
+; NO-SSE-LABEL: inttoptr_v4p0_v4s64:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq %rsi, (%rdi)
+; NO-SSE-NEXT: movq %rdx, 8(%rdi)
+; NO-SSE-NEXT: movq %rcx, 16(%rdi)
+; NO-SSE-NEXT: movq %r8, 24(%rdi)
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: inttoptr_v4p0_v4s64:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: inttoptr_v4p0_v4s64:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: inttoptr_v4p0_v4s64:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = inttoptr <4 x i64> %val to <4 x ptr>
+ ret <4 x ptr> %0
+}
+
+define <8 x ptr> @inttoptr_v8p0_v8s64(<8 x i64> %val) {
+; NO-SSE-LABEL: inttoptr_v8p0_v8s64:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %rdi
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %r10
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %r11
+; NO-SSE-NEXT: movq %rsi, (%rax)
+; NO-SSE-NEXT: movq %rdx, 8(%rax)
+; NO-SSE-NEXT: movq %rcx, 16(%rax)
+; NO-SSE-NEXT: movq %r8, 24(%rax)
+; NO-SSE-NEXT: movq %r9, 32(%rax)
+; NO-SSE-NEXT: movq %rdi, 40(%rax)
+; NO-SSE-NEXT: movq %r10, 48(%rax)
+; NO-SSE-NEXT: movq %r11, 56(%rax)
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: inttoptr_v8p0_v8s64:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: inttoptr_v8p0_v8s64:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: inttoptr_v8p0_v8s64:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = inttoptr <8 x i64> %val to <8 x ptr>
+ ret <8 x ptr> %0
+}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/ptrtoint.ll b/llvm/test/CodeGen/X86/GlobalISel/ptrtoint.ll
deleted file mode 100644
index 01b4360087702..0000000000000
--- a/llvm/test/CodeGen/X86/GlobalISel/ptrtoint.ll
+++ /dev/null
@@ -1,56 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=CHECK
-
-define i1 @ptrtoint_s1_p0(ptr %p) {
-; CHECK-LABEL: ptrtoint_s1_p0:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: # kill: def $al killed $al killed $rax
-; CHECK-NEXT: retq
-entry:
- %0 = ptrtoint ptr %p to i1
- ret i1 %0
-}
-
-define i8 @ptrtoint_s8_p0(ptr %p) {
-; CHECK-LABEL: ptrtoint_s8_p0:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: # kill: def $al killed $al killed $rax
-; CHECK-NEXT: retq
-entry:
- %0 = ptrtoint ptr %p to i8
- ret i8 %0
-}
-
-define i16 @ptrtoint_s16_p0(ptr %p) {
-; CHECK-LABEL: ptrtoint_s16_p0:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: # kill: def $ax killed $ax killed $rax
-; CHECK-NEXT: retq
-entry:
- %0 = ptrtoint ptr %p to i16
- ret i16 %0
-}
-
-define i32 @ptrtoint_s32_p0(ptr %p) {
-; CHECK-LABEL: ptrtoint_s32_p0:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: # kill: def $eax killed $eax killed $rax
-; CHECK-NEXT: retq
-entry:
- %0 = ptrtoint ptr %p to i32
- ret i32 %0
-}
-
-define i64 @ptrtoint_s64_p0(ptr %p) {
-; CHECK-LABEL: ptrtoint_s64_p0:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: retq
-entry:
- %0 = ptrtoint ptr %p to i64
- ret i64 %0
-}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_32.ll b/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_32.ll
new file mode 100644
index 0000000000000..9053ada99ff45
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_32.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=-sse2 -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SCALAR
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SCALAR
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=+avx -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SCALAR
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -mattr=+avx512f -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=SCALAR
+
+define i1 @ptrtoint_s1_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s1_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movl {{[0-9]+}}(%esp), %eax
+; SCALAR-NEXT: # kill: def $al killed $al killed $eax
+; SCALAR-NEXT: retl
+entry:
+ %0 = ptrtoint ptr %p to i1
+ ret i1 %0
+}
+
+define i8 @ptrtoint_s8_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s8_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movl {{[0-9]+}}(%esp), %eax
+; SCALAR-NEXT: # kill: def $al killed $al killed $eax
+; SCALAR-NEXT: retl
+entry:
+ %0 = ptrtoint ptr %p to i8
+ ret i8 %0
+}
+
+define i16 @ptrtoint_s16_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s16_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movl {{[0-9]+}}(%esp), %eax
+; SCALAR-NEXT: # kill: def $ax killed $ax killed $eax
+; SCALAR-NEXT: retl
+entry:
+ %0 = ptrtoint ptr %p to i16
+ ret i16 %0
+}
+
+define i32 @ptrtoint_s32_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s32_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movl {{[0-9]+}}(%esp), %eax
+; SCALAR-NEXT: retl
+entry:
+ %0 = ptrtoint ptr %p to i32
+ ret i32 %0
+}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_64.ll b/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_64.ll
new file mode 100644
index 0000000000000..c55195124c5e5
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/ptrtoint_64.ll
@@ -0,0 +1,166 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=-sse2 -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=SCALAR,NO-SSE
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=SCALAR,SSE
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=+avx -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=SCALAR,AVX
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -mattr=+avx512f -verify-machineinstrs < %s -o - | FileCheck %s --check-prefixes=SCALAR,AVX512
+
+define i1 @ptrtoint_s1_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s1_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movq %rdi, %rax
+; SCALAR-NEXT: # kill: def $al killed $al killed $rax
+; SCALAR-NEXT: retq
+entry:
+ %0 = ptrtoint ptr %p to i1
+ ret i1 %0
+}
+
+define i8 @ptrtoint_s8_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s8_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movq %rdi, %rax
+; SCALAR-NEXT: # kill: def $al killed $al killed $rax
+; SCALAR-NEXT: retq
+entry:
+ %0 = ptrtoint ptr %p to i8
+ ret i8 %0
+}
+
+define i16 @ptrtoint_s16_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s16_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movq %rdi, %rax
+; SCALAR-NEXT: # kill: def $ax killed $ax killed $rax
+; SCALAR-NEXT: retq
+entry:
+ %0 = ptrtoint ptr %p to i16
+ ret i16 %0
+}
+
+define i32 @ptrtoint_s32_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s32_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movq %rdi, %rax
+; SCALAR-NEXT: # kill: def $eax killed $eax killed $rax
+; SCALAR-NEXT: retq
+entry:
+ %0 = ptrtoint ptr %p to i32
+ ret i32 %0
+}
+
+define i64 @ptrtoint_s64_p0(ptr %p) {
+; SCALAR-LABEL: ptrtoint_s64_p0:
+; SCALAR: # %bb.0: # %entry
+; SCALAR-NEXT: movq %rdi, %rax
+; SCALAR-NEXT: retq
+entry:
+ %0 = ptrtoint ptr %p to i64
+ ret i64 %0
+}
+
+define <2 x i1> @ptrtoint_v2s1_v2p0(<2 x ptr> %p) {
+; NO-SSE-LABEL: ptrtoint_v2s1_v2p0:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq %rsi, %rdx
+; NO-SSE-NEXT: # kill: def $al killed $al killed $rax
+; NO-SSE-NEXT: # kill: def $dl killed $dl killed $rdx
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: ptrtoint_v2s1_v2p0:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: ptrtoint_v2s1_v2p0:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: ptrtoint_v2s1_v2p0:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = ptrtoint <2 x ptr> %p to <2 x i1>
+ ret <2 x i1> %0
+}
+
+define <2 x i64> @ptrtoint_v2s64_v2p0(<2 x ptr> %p) {
+; NO-SSE-LABEL: ptrtoint_v2s64_v2p0:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq %rsi, %rdx
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: ptrtoint_v2s64_v2p0:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: ptrtoint_v2s64_v2p0:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: ptrtoint_v2s64_v2p0:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = ptrtoint <2 x ptr> %p to <2 x i64>
+ ret <2 x i64> %0
+}
+
+define <4 x i64> @ptrtoint_v4s64_v4p0(<4 x ptr> %p) {
+; NO-SSE-LABEL: ptrtoint_v4s64_v4p0:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq %rsi, (%rdi)
+; NO-SSE-NEXT: movq %rdx, 8(%rdi)
+; NO-SSE-NEXT: movq %rcx, 16(%rdi)
+; NO-SSE-NEXT: movq %r8, 24(%rdi)
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: ptrtoint_v4s64_v4p0:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: ptrtoint_v4s64_v4p0:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: ptrtoint_v4s64_v4p0:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = ptrtoint <4 x ptr> %p to <4 x i64>
+ ret <4 x i64> %0
+}
+
+define <8 x i64> @ptrtoint_v8s64_v8p0(<8 x ptr> %p) {
+; NO-SSE-LABEL: ptrtoint_v8s64_v8p0:
+; NO-SSE: # %bb.0: # %entry
+; NO-SSE-NEXT: movq %rdi, %rax
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %rdi
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %r10
+; NO-SSE-NEXT: movq {{[0-9]+}}(%rsp), %r11
+; NO-SSE-NEXT: movq %rsi, (%rax)
+; NO-SSE-NEXT: movq %rdx, 8(%rax)
+; NO-SSE-NEXT: movq %rcx, 16(%rax)
+; NO-SSE-NEXT: movq %r8, 24(%rax)
+; NO-SSE-NEXT: movq %r9, 32(%rax)
+; NO-SSE-NEXT: movq %rdi, 40(%rax)
+; NO-SSE-NEXT: movq %r10, 48(%rax)
+; NO-SSE-NEXT: movq %r11, 56(%rax)
+; NO-SSE-NEXT: retq
+;
+; SSE-LABEL: ptrtoint_v8s64_v8p0:
+; SSE: # %bb.0: # %entry
+; SSE-NEXT: retq
+;
+; AVX-LABEL: ptrtoint_v8s64_v8p0:
+; AVX: # %bb.0: # %entry
+; AVX-NEXT: retq
+;
+; AVX512-LABEL: ptrtoint_v8s64_v8p0:
+; AVX512: # %bb.0: # %entry
+; AVX512-NEXT: retq
+entry:
+ %0 = ptrtoint <8 x ptr> %p to <8 x i64>
+ ret <8 x i64> %0
+}
diff --git a/llvm/test/CodeGen/X86/GlobalISel/x86-legalize-ptrtoint.mir b/llvm/test/CodeGen/X86/GlobalISel/x86-legalize-ptrtoint.mir
index 5f0d46f8e913b..cf8f1d9734852 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/x86-legalize-ptrtoint.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/x86-legalize-ptrtoint.mir
@@ -45,11 +45,11 @@ body: |
bb.1.entry:
; CHECK-LABEL: name: ptrtoint_s1_p0
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
- ; CHECK: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s1) = G_PTRTOINT [[LOAD]](p0)
- ; CHECK: [[ANYEXT:%[0-9]+]]:_(s8) = G_ANYEXT [[PTRTOINT]](s1)
- ; CHECK: $al = COPY [[ANYEXT]](s8)
- ; CHECK: RET 0, implicit $al
+ ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[LOAD]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[PTRTOINT]](s32)
+ ; CHECK-NEXT: $al = COPY [[TRUNC]](s8)
+ ; CHECK-NEXT: RET 0, implicit $al
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
%0:_(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
%2:_(s1) = G_PTRTOINT %0(p0)
@@ -74,10 +74,11 @@ body: |
bb.1.entry:
; CHECK-LABEL: name: ptrtoint_s8_p0
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
- ; CHECK: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s8) = G_PTRTOINT [[LOAD]](p0)
- ; CHECK: $al = COPY [[PTRTOINT]](s8)
- ; CHECK: RET 0, implicit $al
+ ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[LOAD]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[PTRTOINT]](s32)
+ ; CHECK-NEXT: $al = COPY [[TRUNC]](s8)
+ ; CHECK-NEXT: RET 0, implicit $al
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
%0:_(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
%2:_(s8) = G_PTRTOINT %0(p0)
@@ -101,10 +102,11 @@ body: |
bb.1.entry:
; CHECK-LABEL: name: ptrtoint_s16_p0
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
- ; CHECK: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s16) = G_PTRTOINT [[LOAD]](p0)
- ; CHECK: $ax = COPY [[PTRTOINT]](s16)
- ; CHECK: RET 0, implicit $ax
+ ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[LOAD]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[PTRTOINT]](s32)
+ ; CHECK-NEXT: $ax = COPY [[TRUNC]](s16)
+ ; CHECK-NEXT: RET 0, implicit $ax
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
%0:_(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
%2:_(s16) = G_PTRTOINT %0(p0)
@@ -128,10 +130,10 @@ body: |
bb.1.entry:
; CHECK-LABEL: name: ptrtoint_s32_p0
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
- ; CHECK: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[LOAD]](p0)
- ; CHECK: $eax = COPY [[PTRTOINT]](s32)
- ; CHECK: RET 0, implicit $eax
+ ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[LOAD]](p0)
+ ; CHECK-NEXT: $eax = COPY [[PTRTOINT]](s32)
+ ; CHECK-NEXT: RET 0, implicit $eax
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
%0:_(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
%2:_(s32) = G_PTRTOINT %0(p0)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/x86-select-ptrtoint.mir b/llvm/test/CodeGen/X86/GlobalISel/x86-select-ptrtoint.mir
index 768120b2739d6..93efd0db27a7d 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/x86-select-ptrtoint.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/x86-select-ptrtoint.mir
@@ -3,116 +3,12 @@
--- |
- define i1 @ptrtoint_s1_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i1
- ret i1 %0
- }
-
- define i8 @ptrtoint_s8_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i8
- ret i8 %0
- }
-
- define i16 @ptrtoint_s16_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i16
- ret i16 %0
- }
-
define i32 @ptrtoint_s32_p0(ptr %p) {
entry:
%0 = ptrtoint ptr %p to i32
ret i32 %0
}
-...
----
-name: ptrtoint_s1_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
- - { id: 2, class: gpr }
- - { id: 3, class: gpr }
-frameInfo:
- maxAlignment: 4
-fixedStack:
- - { id: 0, size: 4, alignment: 16, stack-id: default, isImmutable: true }
-body: |
- bb.1.entry:
- ; CHECK-LABEL: name: ptrtoint_s1_p0
- ; CHECK: [[MOV32rm:%[0-9]+]]:gr32_abcd = MOV32rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[COPY:%[0-9]+]]:gr8 = COPY [[MOV32rm]].sub_8bit
- ; CHECK: $al = COPY [[COPY]]
- ; CHECK: RET 0, implicit $al
- %1:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
- %0:gpr(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- %2:gpr(s1) = G_PTRTOINT %0(p0)
- %3:gpr(s8) = G_ANYEXT %2(s1)
- $al = COPY %3(s8)
- RET 0, implicit $al
-
-...
----
-name: ptrtoint_s8_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
- - { id: 2, class: gpr }
-frameInfo:
- maxAlignment: 4
-fixedStack:
- - { id: 0, size: 4, alignment: 16, stack-id: default, isImmutable: true }
-body: |
- bb.1.entry:
- ; CHECK-LABEL: name: ptrtoint_s8_p0
- ; CHECK: [[MOV32rm:%[0-9]+]]:gr32_abcd = MOV32rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[COPY:%[0-9]+]]:gr8 = COPY [[MOV32rm]].sub_8bit
- ; CHECK: $al = COPY [[COPY]]
- ; CHECK: RET 0, implicit $al
- %1:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
- %0:gpr(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- %2:gpr(s8) = G_PTRTOINT %0(p0)
- $al = COPY %2(s8)
- RET 0, implicit $al
-
-...
----
-name: ptrtoint_s16_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
- - { id: 2, class: gpr }
-frameInfo:
- maxAlignment: 4
-fixedStack:
- - { id: 0, size: 4, alignment: 16, stack-id: default, isImmutable: true }
-body: |
- bb.1.entry:
- ; CHECK-LABEL: name: ptrtoint_s16_p0
- ; CHECK: [[MOV32rm:%[0-9]+]]:gr32 = MOV32rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY [[MOV32rm]].sub_16bit
- ; CHECK: $ax = COPY [[COPY]]
- ; CHECK: RET 0, implicit $ax
- %1:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
- %0:gpr(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
- %2:gpr(s16) = G_PTRTOINT %0(p0)
- $ax = COPY %2(s16)
- RET 0, implicit $ax
-
...
---
name: ptrtoint_s32_p0
@@ -132,8 +28,8 @@ body: |
bb.1.entry:
; CHECK-LABEL: name: ptrtoint_s32_p0
; CHECK: [[MOV32rm:%[0-9]+]]:gr32 = MOV32rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (p0) from %fixed-stack.0, align 16)
- ; CHECK: $eax = COPY [[MOV32rm]]
- ; CHECK: RET 0, implicit $eax
+ ; CHECK-NEXT: $eax = COPY [[MOV32rm]]
+ ; CHECK-NEXT: RET 0, implicit $eax
%1:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
%0:gpr(p0) = G_LOAD %1(p0) :: (invariant load (p0) from %fixed-stack.0, align 16)
%2:gpr(s32) = G_PTRTOINT %0(p0)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/x86_64-legalize-ptrtoint.mir b/llvm/test/CodeGen/X86/GlobalISel/x86_64-legalize-ptrtoint.mir
index 215db7f9302c2..ef0b8c3eab7f3 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/x86_64-legalize-ptrtoint.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/x86_64-legalize-ptrtoint.mir
@@ -48,11 +48,12 @@ body: |
; CHECK-LABEL: name: ptrtoint_s1_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s1) = G_PTRTOINT [[COPY]](p0)
- ; CHECK: [[ANYEXT:%[0-9]+]]:_(s8) = G_ANYEXT [[PTRTOINT]](s1)
- ; CHECK: $al = COPY [[ANYEXT]](s8)
- ; CHECK: RET 0, implicit $al
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[PTRTOINT]](s64)
+ ; CHECK-NEXT: $al = COPY [[TRUNC]](s8)
+ ; CHECK-NEXT: RET 0, implicit $al
%0:_(p0) = COPY $rdi
%1:_(s1) = G_PTRTOINT %0(p0)
%2:_(s8) = G_ANYEXT %1(s1)
@@ -73,10 +74,12 @@ body: |
; CHECK-LABEL: name: ptrtoint_s8_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s8) = G_PTRTOINT [[COPY]](p0)
- ; CHECK: $al = COPY [[PTRTOINT]](s8)
- ; CHECK: RET 0, implicit $al
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[PTRTOINT]](s64)
+ ; CHECK-NEXT: $al = COPY [[TRUNC]](s8)
+ ; CHECK-NEXT: RET 0, implicit $al
%0:_(p0) = COPY $rdi
%1:_(s8) = G_PTRTOINT %0(p0)
$al = COPY %1(s8)
@@ -96,10 +99,12 @@ body: |
; CHECK-LABEL: name: ptrtoint_s16_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s16) = G_PTRTOINT [[COPY]](p0)
- ; CHECK: $ax = COPY [[PTRTOINT]](s16)
- ; CHECK: RET 0, implicit $ax
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[PTRTOINT]](s64)
+ ; CHECK-NEXT: $ax = COPY [[TRUNC]](s16)
+ ; CHECK-NEXT: RET 0, implicit $ax
%0:_(p0) = COPY $rdi
%1:_(s16) = G_PTRTOINT %0(p0)
$ax = COPY %1(s16)
@@ -119,10 +124,12 @@ body: |
; CHECK-LABEL: name: ptrtoint_s32_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p0)
- ; CHECK: $eax = COPY [[PTRTOINT]](s32)
- ; CHECK: RET 0, implicit $eax
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[PTRTOINT]](s64)
+ ; CHECK-NEXT: $eax = COPY [[TRUNC]](s32)
+ ; CHECK-NEXT: RET 0, implicit $eax
%0:_(p0) = COPY $rdi
%1:_(s32) = G_PTRTOINT %0(p0)
$eax = COPY %1(s32)
@@ -142,10 +149,11 @@ body: |
; CHECK-LABEL: name: ptrtoint_s64_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
- ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
- ; CHECK: $rax = COPY [[PTRTOINT]](s64)
- ; CHECK: RET 0, implicit $rax
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $rdi
+ ; CHECK-NEXT: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY]](p0)
+ ; CHECK-NEXT: $rax = COPY [[PTRTOINT]](s64)
+ ; CHECK-NEXT: RET 0, implicit $rax
%0:_(p0) = COPY $rdi
%1:_(s64) = G_PTRTOINT %0(p0)
$rax = COPY %1(s64)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/x86_64-select-ptrtoint.mir b/llvm/test/CodeGen/X86/GlobalISel/x86_64-select-ptrtoint.mir
index 328cf718b2353..9cb67c12106d6 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/x86_64-select-ptrtoint.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/x86_64-select-ptrtoint.mir
@@ -3,138 +3,12 @@
--- |
- define i1 @ptrtoint_s1_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i1
- ret i1 %0
- }
-
- define i8 @ptrtoint_s8_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i8
- ret i8 %0
- }
-
- define i16 @ptrtoint_s16_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i16
- ret i16 %0
- }
-
- define i32 @ptrtoint_s32_p0(ptr %p) {
- entry:
- %0 = ptrtoint ptr %p to i32
- ret i32 %0
- }
-
define i64 @ptrtoint_s64_p0(ptr %p) {
entry:
%0 = ptrtoint ptr %p to i64
ret i64 %0
}
-...
----
-name: ptrtoint_s1_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
- - { id: 2, class: gpr }
-body: |
- bb.1.entry:
- liveins: $rdi
-
- ; CHECK-LABEL: name: ptrtoint_s1_p0
- ; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:gr64_with_sub_8bit = COPY $rdi
- ; CHECK: [[COPY1:%[0-9]+]]:gr8 = COPY [[COPY]].sub_8bit
- ; CHECK: $al = COPY [[COPY1]]
- ; CHECK: RET 0, implicit $al
- %0:gpr(p0) = COPY $rdi
- %1:gpr(s1) = G_PTRTOINT %0(p0)
- %2:gpr(s8) = G_ANYEXT %1(s1)
- $al = COPY %2(s8)
- RET 0, implicit $al
-
-...
----
-name: ptrtoint_s8_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
-body: |
- bb.1.entry:
- liveins: $rdi
-
- ; CHECK-LABEL: name: ptrtoint_s8_p0
- ; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:gr64_with_sub_8bit = COPY $rdi
- ; CHECK: [[COPY1:%[0-9]+]]:gr8 = COPY [[COPY]].sub_8bit
- ; CHECK: $al = COPY [[COPY1]]
- ; CHECK: RET 0, implicit $al
- %0:gpr(p0) = COPY $rdi
- %1:gpr(s8) = G_PTRTOINT %0(p0)
- $al = COPY %1(s8)
- RET 0, implicit $al
-
-...
----
-name: ptrtoint_s16_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
-body: |
- bb.1.entry:
- liveins: $rdi
-
- ; CHECK-LABEL: name: ptrtoint_s16_p0
- ; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rdi
- ; CHECK: [[COPY1:%[0-9]+]]:gr16 = COPY [[COPY]].sub_16bit
- ; CHECK: $ax = COPY [[COPY1]]
- ; CHECK: RET 0, implicit $ax
- %0:gpr(p0) = COPY $rdi
- %1:gpr(s16) = G_PTRTOINT %0(p0)
- $ax = COPY %1(s16)
- RET 0, implicit $ax
-
-...
----
-name: ptrtoint_s32_p0
-alignment: 16
-legalized: true
-regBankSelected: true
-tracksRegLiveness: true
-registers:
- - { id: 0, class: gpr }
- - { id: 1, class: gpr }
-body: |
- bb.1.entry:
- liveins: $rdi
-
- ; CHECK-LABEL: name: ptrtoint_s32_p0
- ; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rdi
- ; CHECK: [[COPY1:%[0-9]+]]:gr32 = COPY [[COPY]].sub_32bit
- ; CHECK: $eax = COPY [[COPY1]]
- ; CHECK: RET 0, implicit $eax
- %0:gpr(p0) = COPY $rdi
- %1:gpr(s32) = G_PTRTOINT %0(p0)
- $eax = COPY %1(s32)
- RET 0, implicit $eax
-
...
---
name: ptrtoint_s64_p0
@@ -151,9 +25,10 @@ body: |
; CHECK-LABEL: name: ptrtoint_s64_p0
; CHECK: liveins: $rdi
- ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rdi
- ; CHECK: $rax = COPY [[COPY]]
- ; CHECK: RET 0, implicit $rax
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY $rdi
+ ; CHECK-NEXT: $rax = COPY [[COPY]]
+ ; CHECK-NEXT: RET 0, implicit $rax
%0:gpr(p0) = COPY $rdi
%1:gpr(s64) = G_PTRTOINT %0(p0)
$rax = COPY %1(s64)
>From 5166b3c06ba7ff87e051a6ec045b57405296e8e9 Mon Sep 17 00:00:00 2001
From: Yohay <yohay.ailon.tevet at gmail.com>
Date: Fri, 9 Jan 2026 23:15:08 +0200
Subject: [PATCH 2/3] Fixed bug that did not allow lowering function with a
vector of pointers argument.
---
llvm/lib/CodeGen/GlobalISel/CallLowering.cpp | 2 +-
llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index 4256e9a42b889..be1d580c1978b 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -228,7 +228,7 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
const AttributeList &Attrs = FuncInfo.getAttributes();
addArgFlagsFromAttributes(Flags, Attrs, OpIdx);
- PointerType *PtrTy = dyn_cast<PointerType>(Arg.Ty->getScalarType());
+ PointerType *PtrTy = dyn_cast<PointerType>(Arg.Ty);
if (PtrTy) {
Flags.setPointer();
Flags.setPointerAddrSpace(PtrTy->getPointerAddressSpace());
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
index 5c6affdae0c5b..ba8b40d133ebb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
@@ -430,9 +430,10 @@ void AMDGPUCallLowering::lowerParameter(MachineIRBuilder &B, ArgInfo &OrigArg,
lowerParameterPtr(PtrReg, B, Offset + FieldOffsets[Idx]);
LLT ArgTy = getLLTForType(*SplitArg.Ty, DL);
- if (SplitArg.Flags[0].isPointer()) {
+ PointerType *OrigPtrTy = dyn_cast<PointerType>(OrigArg.Ty->getScalarType());
+ if (OrigPtrTy) {
// Compensate for losing pointeriness in splitValueTypes.
- LLT PtrTy = LLT::pointer(SplitArg.Flags[0].getPointerAddrSpace(),
+ LLT PtrTy = LLT::pointer(OrigPtrTy->getPointerAddressSpace(),
ArgTy.getScalarSizeInBits());
ArgTy = ArgTy.isVector() ? LLT::vector(ArgTy.getElementCount(), PtrTy)
: PtrTy;
>From 9db86367584230bf95bb421f2c12b16f5c642aca Mon Sep 17 00:00:00 2001
From: Yohay Ailon Tevet <yohay.ailon.tevet at gmail.com>
Date: Tue, 17 Feb 2026 01:14:02 +0200
Subject: [PATCH 3/3] Added support for vector ptrtoint and inttoptr for X86
GlobalISel.
---
.../X86/GISel/X86InstructionSelector.cpp | 6 +++
.../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 53 ++++++++++++++++---
2 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp b/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
index bbc7f464eda4a..b99d6bdff9f37 100644
--- a/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
+++ b/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
@@ -451,6 +451,7 @@ bool X86InstructionSelector::select(MachineInstr &I) {
case TargetOpcode::G_PTRTOINT:
case TargetOpcode::G_TRUNC:
return selectTruncOrPtrToInt(I, MRI, MF);
+ case TargetOpcode::G_BITCAST:
case TargetOpcode::G_INTTOPTR:
case TargetOpcode::G_FREEZE:
return selectCopy(I, MRI);
@@ -897,6 +898,11 @@ bool X86InstructionSelector::selectTruncOrPtrToInt(MachineInstr &I,
if (canTurnIntoCOPY(DstRC, SrcRC))
return selectTurnIntoCOPY(I, MRI, DstReg, DstRC, SrcReg, SrcRC);
+ // If the source and the destination are vectors, this is a ptrtoint of
+ // vectors to vectors, just replace it with a copy.
+ if (DstRB.getID() == X86::VECRRegBankID)
+ return selectTurnIntoCOPY(I, MRI, DstReg, DstRC, SrcReg, SrcRC);
+
if (DstRB.getID() != X86::GPRRegBankID)
return false;
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index fff9edb63b8ae..509c07f1f8d59 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -15,12 +15,14 @@
#include "X86TargetMachine.h"
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
+#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/Type.h"
@@ -77,6 +79,9 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
const LLT v32s16 = LLT::fixed_vector(32, 16);
const LLT v16s32 = LLT::fixed_vector(16, 32);
const LLT v8s64 = LLT::fixed_vector(8, 64);
+ const LLT v8p0 = LLT::fixed_vector(8, p0);
+
+ const LLT v16p0 = LLT::fixed_vector(16, p0);
const LLT s8MaxVector = HasAVX512 ? v64s8 : HasAVX ? v32s8 : v16s8;
const LLT s16MaxVector = HasAVX512 ? v32s16 : HasAVX ? v16s16 : v8s16;
@@ -318,16 +323,50 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
getActionDefinitionsBuilder(G_BRCOND).legalFor({s1});
- // pointer handling
- const std::initializer_list<LLT> PtrTypes32 = {s1, s8, s16, s32};
- const std::initializer_list<LLT> PtrTypes64 = {s1, s8, s16, s32, s64};
+ const bool IsPointer64Bit = TM.getPointerSizeInBits(0) == 64;
getActionDefinitionsBuilder(G_PTRTOINT)
- .legalForCartesianProduct(Is64Bit ? PtrTypes64 : PtrTypes32, {p0})
- .maxScalar(0, sMaxScalar)
- .widenScalarToNextPow2(0, /*Min*/ 8);
+ .legalFor({IsPointer64Bit ? s64 : s32, p0})
+ .legalFor(HasSSE2, {{IsPointer64Bit ? v2s64 : v2s32, v2p0}})
+ .legalFor(HasSSE2 && !IsPointer64Bit, {{v4s32, v4p0}})
+ .legalFor(HasAVX, {{IsPointer64Bit ? v4s64 : v8s32,
+ IsPointer64Bit ? v4p0 : v8p0}})
+ .legalFor(HasAVX512, {{IsPointer64Bit ? v8s64 : v16s32,
+ IsPointer64Bit ? v8p0 : v16p0}})
+ .clampScalarOrElt(0, sMaxScalar, sMaxScalar)
+ .clampMaxNumElements(1, p0,
+ IsPointer64Bit ? s64MaxVector.getNumElements()
+ : s32MaxVector.getNumElements())
+ .scalarize(0);
+
+ getActionDefinitionsBuilder(G_INTTOPTR)
+ .legalFor({{p0, IsPointer64Bit ? s64 : s32}})
+ .legalFor(HasSSE2, {{v2p0, IsPointer64Bit ? v2s64 : v2s32}})
+ .legalFor(HasSSE2 && !IsPointer64Bit, {{v4p0, v4s32}})
+ .legalFor(HasAVX, {{IsPointer64Bit ? v4p0 : v8p0,
+ IsPointer64Bit ? v4s64 : v8s32}})
+ .legalFor(HasAVX512, {{IsPointer64Bit ? v8p0 : v16p0,
+ IsPointer64Bit ? v8s64 : v16s32}})
+ .clampMaxNumElements(0, p0,
+ IsPointer64Bit ? s64MaxVector.getNumElements()
+ : s32MaxVector.getNumElements())
+ .scalarize(0);
- getActionDefinitionsBuilder(G_INTTOPTR).legalFor({{p0, sMaxScalar}});
+ getActionDefinitionsBuilder(G_BITCAST)
+ .legalFor({{p0, sMaxScalar}})
+ .legalIf([=](const LegalityQuery &Query) -> bool {
+ auto SSE2Types = {Is64Bit ? v2p0 : v4p0, v2s64, v4s32, v8s16, v16s8};
+ auto AVXTypes = {Is64Bit ? v4p0 : v8p0, v4s64, v8s32, v16s16, v32s8};
+ auto AVX512Types = {Is64Bit ? v8p0 : v16p0, v8s64, v16s32, v32s16,
+ v64s8};
+ if (HasSSE2 && typeInSet(0, SSE2Types) && typeInSet(1, SSE2Types))
+ return true;
+ if (HasAVX && typeInSet(0, AVXTypes) && typeInSet(1, AVXTypes))
+ return true;
+ if (HasAVX512 && typeInSet(0, AVX512Types) && typeInSet(1, AVX512Types))
+ return true;
+ return false;
+ });
getActionDefinitionsBuilder(G_CONSTANT_POOL).legalFor({p0});
More information about the llvm-commits
mailing list