Skip to content

Commit 2835dcc

Browse files
toppercmemfrob
authored andcommitted
[X86] Remove isel predicates for xgetbv/xsetbv instructions so they can work on Windows.
https://reviews.llvm.org/D56686 was supposed to allow these to work on Windows without needing to enable the xsave feature to match MSVC. It seems this didn't work because the backend isel patterns would still block it. This patch removes the predicates from the isel patterns. Fixes PR51706. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D109097
1 parent fcf98c7 commit 2835dcc

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Target/X86/X86InstrSystem.td

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,17 @@ let SchedRW = [WriteSystem] in {
529529
//===----------------------------------------------------------------------===//
530530
// XSAVE instructions
531531
let SchedRW = [WriteSystem] in {
532-
let Predicates = [HasXSAVE] in {
532+
// NOTE: No HasXSAVE predicate so that these can be used with _xgetbv/_xsetbv
533+
// on Windows without needing to enable the xsave feature to be compatible with
534+
// MSVC.
533535
let Defs = [EDX, EAX], Uses = [ECX] in
534-
def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, PS;
536+
def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, PS;
535537

536538
let Uses = [EDX, EAX, ECX] in
537-
def XSETBV : I<0x01, MRM_D1, (outs), (ins),
538-
"xsetbv",
539-
[(int_x86_xsetbv ECX, EDX, EAX)]>, PS;
539+
def XSETBV : I<0x01, MRM_D1, (outs), (ins),
540+
"xsetbv",
541+
[(int_x86_xsetbv ECX, EDX, EAX)]>, PS;
540542

541-
} // HasXSAVE
542543

543544
let Uses = [EDX, EAX] in {
544545
def XSAVE : I<0xAE, MRM4m, (outs), (ins opaquemem:$dst),

llvm/test/CodeGen/X86/system-intrinsics-xsetbv.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+xsave | FileCheck %s
2-
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+xsave | FileCheck %s --check-prefix=CHECK64
1+
; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s
2+
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=CHECK64
33

44
define void @test_xsetbv(i32 %in, i32 %high, i32 %low) {
55
; CHECK-LABEL: test_xsetbv

0 commit comments

Comments
 (0)