Skip to content

Commit a48305e

Browse files
committed
[X86][CodeGen] Convert masked.load/store to CLOAD/CSTORE node only when vector size = 1
This fixes the crash when building llvm-test-suite with avx512f + cf.
1 parent 27bb2a3 commit a48305e

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4798,8 +4798,8 @@ void SelectionDAGBuilder::visitMaskedStore(const CallInst &I,
47984798
const auto &TTI =
47994799
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
48004800
SDValue StoreNode =
4801-
!IsCompressing && TTI.hasConditionalLoadStoreForType(
4802-
I.getArgOperand(0)->getType()->getScalarType())
4801+
!IsCompressing &&
4802+
TTI.hasConditionalLoadStoreForType(I.getArgOperand(0)->getType())
48034803
? TLI.visitMaskedStore(DAG, sdl, getMemoryRoot(), MMO, Ptr, Src0,
48044804
Mask)
48054805
: DAG.getMaskedStore(getMemoryRoot(), sdl, Src0, Ptr, Offset, Mask,
@@ -4984,8 +4984,8 @@ void SelectionDAGBuilder::visitMaskedLoad(const CallInst &I, bool IsExpanding) {
49844984
// variables.
49854985
SDValue Load;
49864986
SDValue Res;
4987-
if (!IsExpanding && TTI.hasConditionalLoadStoreForType(
4988-
Src0Operand->getType()->getScalarType()))
4987+
if (!IsExpanding &&
4988+
TTI.hasConditionalLoadStoreForType(Src0Operand->getType()))
49894989
Res = TLI.visitMaskedLoad(DAG, sdl, InChain, MMO, Load, Ptr, Src0, Mask);
49904990
else
49914991
Res = Load =

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ bool X86TTIImpl::hasConditionalLoadStoreForType(Type *Ty) const {
185185
// 16/32/64-bit operands.
186186
// TODO: Support f32/f64 with VMOVSS/VMOVSD with zero mask when it's
187187
// profitable.
188-
if (!Ty->isIntegerTy())
188+
auto *VTy = dyn_cast<FixedVectorType>(Ty);
189+
if (!Ty->isIntegerTy() && (!VTy || VTy->getNumElements() != 1))
189190
return false;
190-
switch (cast<IntegerType>(Ty)->getBitWidth()) {
191+
auto *ScalarTy = Ty->getScalarType();
192+
switch (cast<IntegerType>(ScalarTy)->getBitWidth()) {
191193
default:
192194
return false;
193195
case 16:

llvm/test/CodeGen/X86/apx/cf.ll

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -mtriple=x86_64 -mattr=+cf -verify-machineinstrs | FileCheck %s
2+
; RUN: llc < %s -mtriple=x86_64 -mattr=+cf,+avx512f -verify-machineinstrs | FileCheck %s
33

44
define void @basic(i32 %a, ptr %b, ptr %p, ptr %q) {
55
; CHECK-LABEL: basic:
@@ -103,3 +103,24 @@ entry:
103103
%2 = bitcast <1 x i64> %1 to i64
104104
ret i64 %2
105105
}
106+
107+
define void @no_crash(ptr %p, <4 x i1> %cond1, <4 x i1> %cond2) {
108+
; CHECK-LABEL: no_crash:
109+
; CHECK: # %bb.0: # %entry
110+
; CHECK-NEXT: vpslld $31, %xmm1, %xmm1
111+
; CHECK-NEXT: vptestmd %zmm1, %zmm1, %k0
112+
; CHECK-NEXT: kshiftlw $12, %k0, %k0
113+
; CHECK-NEXT: kshiftrw $12, %k0, %k1
114+
; CHECK-NEXT: vpslld $31, %xmm0, %xmm0
115+
; CHECK-NEXT: vptestmd %zmm0, %zmm0, %k0
116+
; CHECK-NEXT: kshiftlw $12, %k0, %k0
117+
; CHECK-NEXT: kshiftrw $12, %k0, %k2
118+
; CHECK-NEXT: vmovdqu64 (%rdi), %zmm0 {%k2} {z}
119+
; CHECK-NEXT: vmovdqu64 %zmm0, (%rdi) {%k1}
120+
; CHECK-NEXT: vzeroupper
121+
; CHECK-NEXT: retq
122+
entry:
123+
%0 = call <4 x i64> @llvm.masked.load.v4i64.p0(ptr %p, i32 8, <4 x i1> %cond1, <4 x i64> poison)
124+
call void @llvm.masked.store.v4i64.p0(<4 x i64> %0, ptr %p, i32 8, <4 x i1> %cond2)
125+
ret void
126+
}

0 commit comments

Comments
 (0)