From cfe316007fb8492535d697717c24ce72621a8d5e Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 18 Dec 2019 10:41:34 -0800 Subject: [PATCH] [SelectionDAGBuilder] Use getConstant instead of getTargetConstant to build the offset for struct types in getUniformBase. getTargetConstant prevents any optimizations from operating on the value and basically says its already been iseled. But since we want the index to be in a register, this isn't true. Prior to this we were generating a vbroadcast with an immediate argument which is illegal and was flagged by the expensive checks bot. --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 4 ++-- llvm/test/CodeGen/X86/masked_gather.ll | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 735ac67..c69fe55 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4390,8 +4390,8 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index, } auto *CI = cast(C); Scale = DAG.getTargetConstant(1, SDB->getCurSDLoc(), TLI.getPointerTy(DL)); - Index = DAG.getTargetConstant(SL->getElementOffset(CI->getZExtValue()), - SDB->getCurSDLoc(), TLI.getPointerTy(DL)); + Index = DAG.getConstant(SL->getElementOffset(CI->getZExtValue()), + SDB->getCurSDLoc(), TLI.getPointerTy(DL)); } else { Scale = DAG.getTargetConstant( DL.getTypeAllocSize(GEP->getResultElementType()), diff --git a/llvm/test/CodeGen/X86/masked_gather.ll b/llvm/test/CodeGen/X86/masked_gather.ll index dd41009..7ea2cac 100644 --- a/llvm/test/CodeGen/X86/masked_gather.ll +++ b/llvm/test/CodeGen/X86/masked_gather.ll @@ -1725,13 +1725,14 @@ define <8 x i32> @gather_v8i32_v8i32(<8 x i32> %trigger) { ; AVX512-LABEL: gather_v8i32_v8i32: ; AVX512: # %bb.0: ; AVX512-NEXT: # kill: def $ymm0 killed $ymm0 def $zmm0 -; AVX512-NEXT: vptestnmd %zmm0, %zmm0, %k1 -; AVX512-NEXT: kshiftlw $8, %k1, %k0 -; AVX512-NEXT: kshiftrw $8, %k0, %k2 +; AVX512-NEXT: vptestnmd %zmm0, %zmm0, %k0 +; AVX512-NEXT: kshiftlw $8, %k0, %k0 +; AVX512-NEXT: kshiftrw $8, %k0, %k1 ; AVX512-NEXT: vpbroadcastd {{.*#+}} zmm0 = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3] +; AVX512-NEXT: kmovw %k1, %k2 ; AVX512-NEXT: vpgatherdd c(,%zmm0,4), %zmm1 {%k2} -; AVX512-NEXT: vpbroadcastq $28, %zmm0 -; AVX512-NEXT: vpgatherqd c(,%zmm0), %ymm2 {%k1} +; AVX512-NEXT: vpbroadcastd {{.*#+}} zmm0 = [28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28] +; AVX512-NEXT: vpgatherdd c(,%zmm0), %zmm2 {%k1} ; AVX512-NEXT: vpaddd %ymm2, %ymm2, %ymm0 ; AVX512-NEXT: vpaddd %ymm0, %ymm1, %ymm0 ; AVX512-NEXT: retq -- 2.7.4