2017-09-28 01:26:01 +02:00
|
|
|
//===- ScalarizeMaskedMemIntrin.cpp - Scalarize unsupported masked mem ----===//
|
|
|
|
// instrinsics
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass replaces masked memory intrinsics - when unsupported by the target
|
|
|
|
// - with a chain of basic blocks, that deal with the elements one-by-one if the
|
|
|
|
// appropriate mask bit is set.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
#include "llvm/Transforms/Scalar/ScalarizeMaskedMemIntrin.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2021-01-28 16:13:17 +01:00
|
|
|
#include "llvm/Analysis/DomTreeUpdater.h"
|
2017-05-15 13:30:54 +02:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/Constant.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2021-01-28 16:13:17 +01:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-05-15 13:30:54 +02:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/IR/InstrTypes.h"
|
|
|
|
#include "llvm/IR/Instruction.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2017-09-08 01:27:44 +02:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 22:15:01 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
2020-12-08 19:08:09 +01:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2021-01-28 19:28:36 +01:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2017-09-28 01:26:01 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "scalarize-masked-mem-intrin"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
class ScalarizeMaskedMemIntrinLegacyPass : public FunctionPass {
|
2017-05-15 13:30:54 +02:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2017-09-28 01:26:01 +02:00
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
explicit ScalarizeMaskedMemIntrinLegacyPass() : FunctionPass(ID) {
|
|
|
|
initializeScalarizeMaskedMemIntrinLegacyPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
2017-09-28 01:26:01 +02:00
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
bool runOnFunction(Function &F) override;
|
|
|
|
|
|
|
|
StringRef getPassName() const override {
|
|
|
|
return "Scalarize Masked Memory Intrinsics";
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
2021-01-28 16:13:17 +01:00
|
|
|
AU.addPreserved<DominatorTreeWrapperPass>();
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
};
|
2017-09-28 01:26:01 +02:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2020-12-03 17:43:30 +01:00
|
|
|
static bool optimizeBlock(BasicBlock &BB, bool &ModifiedDT,
|
2021-01-28 16:13:17 +01:00
|
|
|
const TargetTransformInfo &TTI, const DataLayout &DL,
|
|
|
|
DomTreeUpdater *DTU);
|
2020-12-03 17:43:30 +01:00
|
|
|
static bool optimizeCallInst(CallInst *CI, bool &ModifiedDT,
|
2020-12-03 20:02:47 +01:00
|
|
|
const TargetTransformInfo &TTI,
|
2021-01-28 16:13:17 +01:00
|
|
|
const DataLayout &DL, DomTreeUpdater *DTU);
|
2020-12-03 17:43:30 +01:00
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
char ScalarizeMaskedMemIntrinLegacyPass::ID = 0;
|
2017-09-28 01:26:01 +02:00
|
|
|
|
2021-01-18 16:53:08 +01:00
|
|
|
INITIALIZE_PASS_BEGIN(ScalarizeMaskedMemIntrinLegacyPass, DEBUG_TYPE,
|
|
|
|
"Scalarize unsupported masked memory intrinsics", false,
|
|
|
|
false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
2021-01-28 16:13:17 +01:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
2021-01-18 16:53:08 +01:00
|
|
|
INITIALIZE_PASS_END(ScalarizeMaskedMemIntrinLegacyPass, DEBUG_TYPE,
|
|
|
|
"Scalarize unsupported masked memory intrinsics", false,
|
|
|
|
false)
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
FunctionPass *llvm::createScalarizeMaskedMemIntrinLegacyPass() {
|
|
|
|
return new ScalarizeMaskedMemIntrinLegacyPass();
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 00:31:42 +02:00
|
|
|
static bool isConstantIntVector(Value *Mask) {
|
|
|
|
Constant *C = dyn_cast<Constant>(Mask);
|
|
|
|
if (!C)
|
|
|
|
return false;
|
|
|
|
|
2020-07-09 20:51:03 +02:00
|
|
|
unsigned NumElts = cast<FixedVectorType>(Mask->getType())->getNumElements();
|
2018-09-28 00:31:42 +02:00
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
|
|
|
Constant *CElt = C->getAggregateElement(i);
|
|
|
|
if (!CElt || !isa<ConstantInt>(CElt))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-11 09:59:52 +01:00
|
|
|
static unsigned adjustForEndian(const DataLayout &DL, unsigned VectorWidth,
|
|
|
|
unsigned Idx) {
|
|
|
|
return DL.isBigEndian() ? VectorWidth - 1 - Idx : Idx;
|
|
|
|
}
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
// Translate a masked load intrinsic like
|
|
|
|
// <16 x i32 > @llvm.masked.load( <16 x i32>* %addr, i32 align,
|
|
|
|
// <16 x i1> %mask, <16 x i32> %passthru)
|
|
|
|
// to a chain of basic blocks, with loading element one-by-one if
|
|
|
|
// the appropriate mask bit is set
|
|
|
|
//
|
|
|
|
// %1 = bitcast i8* %addr to i32*
|
|
|
|
// %2 = extractelement <16 x i1> %mask, i32 0
|
2018-09-27 23:28:39 +02:00
|
|
|
// br i1 %2, label %cond.load, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.load: ; preds = %0
|
2018-09-27 23:28:39 +02:00
|
|
|
// %3 = getelementptr i32* %1, i32 0
|
|
|
|
// %4 = load i32* %3
|
2018-09-27 23:28:52 +02:00
|
|
|
// %5 = insertelement <16 x i32> %passthru, i32 %4, i32 0
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else
|
|
|
|
//
|
|
|
|
// else: ; preds = %0, %cond.load
|
2018-09-27 23:28:39 +02:00
|
|
|
// %res.phi.else = phi <16 x i32> [ %5, %cond.load ], [ undef, %0 ]
|
|
|
|
// %6 = extractelement <16 x i1> %mask, i32 1
|
|
|
|
// br i1 %6, label %cond.load1, label %else2
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.load1: ; preds = %else
|
2018-09-27 23:28:39 +02:00
|
|
|
// %7 = getelementptr i32* %1, i32 1
|
|
|
|
// %8 = load i32* %7
|
|
|
|
// %9 = insertelement <16 x i32> %res.phi.else, i32 %8, i32 1
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else2
|
|
|
|
//
|
|
|
|
// else2: ; preds = %else, %cond.load1
|
2018-09-27 23:28:39 +02:00
|
|
|
// %res.phi.else3 = phi <16 x i32> [ %9, %cond.load1 ], [ %res.phi.else, %else ]
|
|
|
|
// %10 = extractelement <16 x i1> %mask, i32 2
|
|
|
|
// br i1 %10, label %cond.load4, label %else5
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedLoad(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU, bool &ModifiedDT) {
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *Ptr = CI->getArgOperand(0);
|
|
|
|
Value *Alignment = CI->getArgOperand(1);
|
|
|
|
Value *Mask = CI->getArgOperand(2);
|
|
|
|
Value *Src0 = CI->getArgOperand(3);
|
|
|
|
|
2020-01-23 11:33:12 +01:00
|
|
|
const Align AlignVal = cast<ConstantInt>(Alignment)->getAlignValue();
|
2020-07-09 20:51:03 +02:00
|
|
|
VectorType *VecType = cast<FixedVectorType>(CI->getType());
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2018-09-28 00:31:40 +02:00
|
|
|
Type *EltTy = VecType->getElementType();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
BasicBlock *IfBlock = CI->getParent();
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
|
|
|
// Short-cut if the mask is all-true.
|
2018-09-27 23:28:41 +02:00
|
|
|
if (isa<Constant>(Mask) && cast<Constant>(Mask)->isAllOnesValue()) {
|
2019-02-01 21:44:24 +01:00
|
|
|
Value *NewI = Builder.CreateAlignedLoad(VecType, Ptr, AlignVal);
|
2017-05-15 13:30:54 +02:00
|
|
|
CI->replaceAllUsesWith(NewI);
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust alignment for the scalar instruction.
|
2020-01-23 11:33:12 +01:00
|
|
|
const Align AdjustedAlignVal =
|
|
|
|
commonAlignment(AlignVal, EltTy->getPrimitiveSizeInBits() / 8);
|
2019-03-09 03:08:41 +01:00
|
|
|
// Bitcast %addr from i8* to EltTy*
|
2017-05-15 13:30:54 +02:00
|
|
|
Type *NewPtrType =
|
2019-03-09 03:08:41 +01:00
|
|
|
EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace());
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType);
|
2020-07-09 20:51:03 +02:00
|
|
|
unsigned VectorWidth = cast<FixedVectorType>(VecType)->getNumElements();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// The result vector
|
2018-09-27 23:28:52 +02:00
|
|
|
Value *VResult = Src0;
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2018-09-28 00:31:42 +02:00
|
|
|
if (isConstantIntVector(Mask)) {
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
2018-09-27 23:28:46 +02:00
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue())
|
2017-05-15 13:30:54 +02:00
|
|
|
continue;
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx);
|
2020-01-23 11:33:12 +01:00
|
|
|
LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AdjustedAlignVal);
|
2019-03-09 03:08:41 +01:00
|
|
|
VResult = Builder.CreateInsertElement(VResult, Load, Idx);
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
2018-09-27 23:28:52 +02:00
|
|
|
CI->replaceAllUsesWith(VResult);
|
2017-05-15 13:30:54 +02:00
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-01 00:58:15 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
|
|
|
// %res.phi.else3 = phi <16 x i32> [ %11, %cond.load1 ], [ %res.phi.else, %else ]
|
2019-08-01 00:58:15 +02:00
|
|
|
// %mask_1 = and i16 %scalar_mask, i32 1 << Idx
|
|
|
|
// %cond = icmp ne i16 %mask_1, 0
|
2018-09-27 20:01:48 +02:00
|
|
|
// br i1 %mask_1, label %cond.load, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-01 00:58:15 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx);
|
|
|
|
}
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
|
|
|
// %EltAddr = getelementptr i32* %1, i32 0
|
|
|
|
// %Elt = load i32* %EltAddr
|
|
|
|
// VResult = insertelement <16 x i32> VResult, i32 %Elt, i32 Idx
|
|
|
|
//
|
2021-01-28 19:28:36 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2021-01-28 19:28:36 +01:00
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.load");
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx);
|
2020-01-23 11:33:12 +01:00
|
|
|
LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AdjustedAlignVal);
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *NewVResult = Builder.CreateInsertElement(VResult, Load, Idx);
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 19:28:36 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
2018-10-30 21:33:58 +01:00
|
|
|
BasicBlock *PrevIfBlock = IfBlock;
|
2017-05-15 13:30:54 +02:00
|
|
|
IfBlock = NewIfBlock;
|
2018-09-27 23:28:52 +02:00
|
|
|
|
|
|
|
// Create the phi to join the new and previous value.
|
2021-01-28 19:28:36 +01:00
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
2018-09-27 23:28:52 +02:00
|
|
|
PHINode *Phi = Builder.CreatePHI(VecType, 2, "res.phi.else");
|
|
|
|
Phi->addIncoming(NewVResult, CondBlock);
|
|
|
|
Phi->addIncoming(VResult, PrevIfBlock);
|
|
|
|
VResult = Phi;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 23:28:52 +02:00
|
|
|
CI->replaceAllUsesWith(VResult);
|
2017-05-15 13:30:54 +02:00
|
|
|
CI->eraseFromParent();
|
2019-03-09 00:03:43 +01:00
|
|
|
|
|
|
|
ModifiedDT = true;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Translate a masked store intrinsic, like
|
|
|
|
// void @llvm.masked.store(<16 x i32> %src, <16 x i32>* %addr, i32 align,
|
|
|
|
// <16 x i1> %mask)
|
|
|
|
// to a chain of basic blocks, that stores element one-by-one if
|
|
|
|
// the appropriate mask bit is set
|
|
|
|
//
|
|
|
|
// %1 = bitcast i8* %addr to i32*
|
|
|
|
// %2 = extractelement <16 x i1> %mask, i32 0
|
2018-09-27 23:28:39 +02:00
|
|
|
// br i1 %2, label %cond.store, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.store: ; preds = %0
|
2018-09-27 23:28:39 +02:00
|
|
|
// %3 = extractelement <16 x i32> %val, i32 0
|
|
|
|
// %4 = getelementptr i32* %1, i32 0
|
|
|
|
// store i32 %3, i32* %4
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else
|
|
|
|
//
|
|
|
|
// else: ; preds = %0, %cond.store
|
2018-09-27 23:28:39 +02:00
|
|
|
// %5 = extractelement <16 x i1> %mask, i32 1
|
|
|
|
// br i1 %5, label %cond.store1, label %else2
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.store1: ; preds = %else
|
2018-09-27 23:28:39 +02:00
|
|
|
// %6 = extractelement <16 x i32> %val, i32 1
|
|
|
|
// %7 = getelementptr i32* %1, i32 1
|
|
|
|
// store i32 %6, i32* %7
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else2
|
|
|
|
// . . .
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedStore(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU, bool &ModifiedDT) {
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *Src = CI->getArgOperand(0);
|
|
|
|
Value *Ptr = CI->getArgOperand(1);
|
|
|
|
Value *Alignment = CI->getArgOperand(2);
|
|
|
|
Value *Mask = CI->getArgOperand(3);
|
|
|
|
|
2020-01-23 16:18:34 +01:00
|
|
|
const Align AlignVal = cast<ConstantInt>(Alignment)->getAlignValue();
|
2020-07-09 20:51:03 +02:00
|
|
|
auto *VecType = cast<VectorType>(Src->getType());
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
Type *EltTy = VecType->getElementType();
|
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
|
|
|
// Short-cut if the mask is all-true.
|
2018-09-27 23:28:41 +02:00
|
|
|
if (isa<Constant>(Mask) && cast<Constant>(Mask)->isAllOnesValue()) {
|
2017-05-15 13:30:54 +02:00
|
|
|
Builder.CreateAlignedStore(Src, Ptr, AlignVal);
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust alignment for the scalar instruction.
|
2020-01-23 16:18:34 +01:00
|
|
|
const Align AdjustedAlignVal =
|
|
|
|
commonAlignment(AlignVal, EltTy->getPrimitiveSizeInBits() / 8);
|
2019-03-09 03:08:41 +01:00
|
|
|
// Bitcast %addr from i8* to EltTy*
|
2017-05-15 13:30:54 +02:00
|
|
|
Type *NewPtrType =
|
2019-03-09 03:08:41 +01:00
|
|
|
EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace());
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType);
|
2020-07-09 20:51:03 +02:00
|
|
|
unsigned VectorWidth = cast<FixedVectorType>(VecType)->getNumElements();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2018-09-28 00:31:42 +02:00
|
|
|
if (isConstantIntVector(Mask)) {
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
2018-09-27 23:28:46 +02:00
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue())
|
2017-05-15 13:30:54 +02:00
|
|
|
continue;
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *OneElt = Builder.CreateExtractElement(Src, Idx);
|
|
|
|
Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx);
|
2020-01-23 16:18:34 +01:00
|
|
|
Builder.CreateAlignedStore(OneElt, Gep, AdjustedAlignVal);
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-01 00:58:15 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
// %mask_1 = and i16 %scalar_mask, i32 1 << Idx
|
|
|
|
// %cond = icmp ne i16 %mask_1, 0
|
2018-09-27 20:01:48 +02:00
|
|
|
// br i1 %mask_1, label %cond.store, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-01 00:58:15 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx);
|
|
|
|
}
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
|
|
|
// %OneElt = extractelement <16 x i32> %Src, i32 Idx
|
|
|
|
// %EltAddr = getelementptr i32* %1, i32 0
|
|
|
|
// %store i32 %OneElt, i32* %EltAddr
|
|
|
|
//
|
2021-01-28 19:39:28 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2021-01-28 19:39:28 +01:00
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.store");
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *OneElt = Builder.CreateExtractElement(Src, Idx);
|
|
|
|
Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx);
|
2020-01-23 16:18:34 +01:00
|
|
|
Builder.CreateAlignedStore(OneElt, Gep, AdjustedAlignVal);
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 19:39:28 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
2019-03-09 00:03:43 +01:00
|
|
|
|
|
|
|
ModifiedDT = true;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Translate a masked gather intrinsic like
|
|
|
|
// <16 x i32 > @llvm.masked.gather.v16i32( <16 x i32*> %Ptrs, i32 4,
|
|
|
|
// <16 x i1> %Mask, <16 x i32> %Src)
|
|
|
|
// to a chain of basic blocks, with loading element one-by-one if
|
|
|
|
// the appropriate mask bit is set
|
|
|
|
//
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Ptrs = getelementptr i32, i32* %base, <16 x i64> %ind
|
|
|
|
// %Mask0 = extractelement <16 x i1> %Mask, i32 0
|
|
|
|
// br i1 %Mask0, label %cond.load, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.load:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Ptr0 = extractelement <16 x i32*> %Ptrs, i32 0
|
|
|
|
// %Load0 = load i32, i32* %Ptr0, align 4
|
|
|
|
// %Res0 = insertelement <16 x i32> undef, i32 %Load0, i32 0
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else
|
|
|
|
//
|
|
|
|
// else:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %res.phi.else = phi <16 x i32>[%Res0, %cond.load], [undef, %0]
|
|
|
|
// %Mask1 = extractelement <16 x i1> %Mask, i32 1
|
|
|
|
// br i1 %Mask1, label %cond.load1, label %else2
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.load1:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Ptr1 = extractelement <16 x i32*> %Ptrs, i32 1
|
|
|
|
// %Load1 = load i32, i32* %Ptr1, align 4
|
|
|
|
// %Res1 = insertelement <16 x i32> %res.phi.else, i32 %Load1, i32 1
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else2
|
|
|
|
// . . .
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Result = select <16 x i1> %Mask, <16 x i32> %res.phi.select, <16 x i32> %Src
|
2017-05-15 13:30:54 +02:00
|
|
|
// ret <16 x i32> %Result
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedGather(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU, bool &ModifiedDT) {
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *Ptrs = CI->getArgOperand(0);
|
|
|
|
Value *Alignment = CI->getArgOperand(1);
|
|
|
|
Value *Mask = CI->getArgOperand(2);
|
|
|
|
Value *Src0 = CI->getArgOperand(3);
|
|
|
|
|
2020-07-09 20:51:03 +02:00
|
|
|
auto *VecType = cast<FixedVectorType>(CI->getType());
|
2019-02-01 21:44:24 +01:00
|
|
|
Type *EltTy = VecType->getElementType();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
BasicBlock *IfBlock = CI->getParent();
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
2020-07-03 10:06:43 +02:00
|
|
|
MaybeAlign AlignVal = cast<ConstantInt>(Alignment)->getMaybeAlignValue();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
|
|
|
// The result vector
|
2018-09-27 23:28:59 +02:00
|
|
|
Value *VResult = Src0;
|
2017-05-15 13:30:54 +02:00
|
|
|
unsigned VectorWidth = VecType->getNumElements();
|
|
|
|
|
|
|
|
// Shorten the way if the mask is a vector of constants.
|
2018-09-28 00:31:42 +02:00
|
|
|
if (isConstantIntVector(Mask)) {
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
2018-09-27 23:28:46 +02:00
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue())
|
2017-05-15 13:30:54 +02:00
|
|
|
continue;
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *Ptr = Builder.CreateExtractElement(Ptrs, Idx, "Ptr" + Twine(Idx));
|
2020-07-03 10:06:43 +02:00
|
|
|
LoadInst *Load =
|
|
|
|
Builder.CreateAlignedLoad(EltTy, Ptr, AlignVal, "Load" + Twine(Idx));
|
2019-03-09 03:08:41 +01:00
|
|
|
VResult =
|
|
|
|
Builder.CreateInsertElement(VResult, Load, Idx, "Res" + Twine(Idx));
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
2018-09-27 23:28:59 +02:00
|
|
|
CI->replaceAllUsesWith(VResult);
|
2017-05-15 13:30:54 +02:00
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-01 00:58:15 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
// %Mask1 = and i16 %scalar_mask, i32 1 << Idx
|
|
|
|
// %cond = icmp ne i16 %mask_1, 0
|
2018-09-27 20:01:48 +02:00
|
|
|
// br i1 %Mask1, label %cond.load, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
|
2019-08-01 00:58:15 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-01 00:58:15 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx, "Mask" + Twine(Idx));
|
|
|
|
}
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
|
|
|
// %EltAddr = getelementptr i32* %1, i32 0
|
|
|
|
// %Elt = load i32* %EltAddr
|
|
|
|
// VResult = insertelement <16 x i32> VResult, i32 %Elt, i32 Idx
|
|
|
|
//
|
2021-01-28 19:58:29 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2021-01-28 19:58:29 +01:00
|
|
|
|
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.load");
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2021-01-28 19:58:29 +01:00
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *Ptr = Builder.CreateExtractElement(Ptrs, Idx, "Ptr" + Twine(Idx));
|
2020-07-03 10:06:43 +02:00
|
|
|
LoadInst *Load =
|
|
|
|
Builder.CreateAlignedLoad(EltTy, Ptr, AlignVal, "Load" + Twine(Idx));
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *NewVResult =
|
|
|
|
Builder.CreateInsertElement(VResult, Load, Idx, "Res" + Twine(Idx));
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 19:58:29 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
2018-10-30 21:33:58 +01:00
|
|
|
BasicBlock *PrevIfBlock = IfBlock;
|
2017-05-15 13:30:54 +02:00
|
|
|
IfBlock = NewIfBlock;
|
2018-09-27 23:28:59 +02:00
|
|
|
|
2021-01-28 19:58:29 +01:00
|
|
|
// Create the phi to join the new and previous value.
|
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
2018-09-27 23:28:59 +02:00
|
|
|
PHINode *Phi = Builder.CreatePHI(VecType, 2, "res.phi.else");
|
|
|
|
Phi->addIncoming(NewVResult, CondBlock);
|
|
|
|
Phi->addIncoming(VResult, PrevIfBlock);
|
|
|
|
VResult = Phi;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 23:28:59 +02:00
|
|
|
CI->replaceAllUsesWith(VResult);
|
2017-05-15 13:30:54 +02:00
|
|
|
CI->eraseFromParent();
|
2019-03-09 00:03:43 +01:00
|
|
|
|
|
|
|
ModifiedDT = true;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Translate a masked scatter intrinsic, like
|
|
|
|
// void @llvm.masked.scatter.v16i32(<16 x i32> %Src, <16 x i32*>* %Ptrs, i32 4,
|
|
|
|
// <16 x i1> %Mask)
|
|
|
|
// to a chain of basic blocks, that stores element one-by-one if
|
|
|
|
// the appropriate mask bit is set.
|
|
|
|
//
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Ptrs = getelementptr i32, i32* %ptr, <16 x i64> %ind
|
|
|
|
// %Mask0 = extractelement <16 x i1> %Mask, i32 0
|
|
|
|
// br i1 %Mask0, label %cond.store, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.store:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Elt0 = extractelement <16 x i32> %Src, i32 0
|
|
|
|
// %Ptr0 = extractelement <16 x i32*> %Ptrs, i32 0
|
|
|
|
// store i32 %Elt0, i32* %Ptr0, align 4
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else
|
|
|
|
//
|
|
|
|
// else:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Mask1 = extractelement <16 x i1> %Mask, i32 1
|
|
|
|
// br i1 %Mask1, label %cond.store1, label %else2
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
|
|
|
// cond.store1:
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Elt1 = extractelement <16 x i32> %Src, i32 1
|
|
|
|
// %Ptr1 = extractelement <16 x i32*> %Ptrs, i32 1
|
|
|
|
// store i32 %Elt1, i32* %Ptr1, align 4
|
2017-05-15 13:30:54 +02:00
|
|
|
// br label %else2
|
|
|
|
// . . .
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedScatter(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU, bool &ModifiedDT) {
|
2017-05-15 13:30:54 +02:00
|
|
|
Value *Src = CI->getArgOperand(0);
|
|
|
|
Value *Ptrs = CI->getArgOperand(1);
|
|
|
|
Value *Alignment = CI->getArgOperand(2);
|
|
|
|
Value *Mask = CI->getArgOperand(3);
|
|
|
|
|
2020-07-09 20:51:03 +02:00
|
|
|
auto *SrcFVTy = cast<FixedVectorType>(Src->getType());
|
|
|
|
|
2020-04-10 23:23:20 +02:00
|
|
|
assert(
|
|
|
|
isa<VectorType>(Ptrs->getType()) &&
|
|
|
|
isa<PointerType>(cast<VectorType>(Ptrs->getType())->getElementType()) &&
|
|
|
|
"Vector of pointers is expected in masked scatter intrinsic");
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
2020-07-03 10:06:43 +02:00
|
|
|
MaybeAlign AlignVal = cast<ConstantInt>(Alignment)->getMaybeAlignValue();
|
2020-07-09 20:51:03 +02:00
|
|
|
unsigned VectorWidth = SrcFVTy->getNumElements();
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Shorten the way if the mask is a vector of constants.
|
2018-09-28 00:31:42 +02:00
|
|
|
if (isConstantIntVector(Mask)) {
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
2019-06-03 00:52:34 +02:00
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue())
|
2017-05-15 13:30:54 +02:00
|
|
|
continue;
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *OneElt =
|
|
|
|
Builder.CreateExtractElement(Src, Idx, "Elt" + Twine(Idx));
|
|
|
|
Value *Ptr = Builder.CreateExtractElement(Ptrs, Idx, "Ptr" + Twine(Idx));
|
2017-05-15 13:30:54 +02:00
|
|
|
Builder.CreateAlignedStore(OneElt, Ptr, AlignVal);
|
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2018-09-27 23:28:41 +02:00
|
|
|
|
2019-08-01 00:58:15 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
// %Mask1 = and i16 %scalar_mask, i32 1 << Idx
|
|
|
|
// %cond = icmp ne i16 %mask_1, 0
|
2018-09-27 20:01:48 +02:00
|
|
|
// br i1 %Mask1, label %cond.store, label %else
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2019-08-01 00:58:15 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-01 00:58:15 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx, "Mask" + Twine(Idx));
|
|
|
|
}
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
2018-09-27 23:28:39 +02:00
|
|
|
// %Elt1 = extractelement <16 x i32> %Src, i32 1
|
|
|
|
// %Ptr1 = extractelement <16 x i32*> %Ptrs, i32 1
|
|
|
|
// %store i32 %Elt1, i32* %Ptr1
|
2017-05-15 13:30:54 +02:00
|
|
|
//
|
2021-01-28 20:15:34 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2021-01-28 20:15:34 +01:00
|
|
|
|
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.store");
|
2017-05-15 13:30:54 +02:00
|
|
|
|
2021-01-28 20:15:34 +01:00
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2019-03-09 03:08:41 +01:00
|
|
|
Value *OneElt = Builder.CreateExtractElement(Src, Idx, "Elt" + Twine(Idx));
|
|
|
|
Value *Ptr = Builder.CreateExtractElement(Ptrs, Idx, "Ptr" + Twine(Idx));
|
2017-05-15 13:30:54 +02:00
|
|
|
Builder.CreateAlignedStore(OneElt, Ptr, AlignVal);
|
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 20:15:34 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
2019-03-09 00:03:43 +01:00
|
|
|
|
|
|
|
ModifiedDT = true;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedExpandLoad(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU, bool &ModifiedDT) {
|
2019-03-21 18:38:52 +01:00
|
|
|
Value *Ptr = CI->getArgOperand(0);
|
|
|
|
Value *Mask = CI->getArgOperand(1);
|
|
|
|
Value *PassThru = CI->getArgOperand(2);
|
|
|
|
|
2020-07-09 20:51:03 +02:00
|
|
|
auto *VecType = cast<FixedVectorType>(CI->getType());
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
Type *EltTy = VecType->getElementType();
|
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
BasicBlock *IfBlock = CI->getParent();
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
|
|
|
unsigned VectorWidth = VecType->getNumElements();
|
|
|
|
|
|
|
|
// The result vector
|
|
|
|
Value *VResult = PassThru;
|
|
|
|
|
2019-08-02 22:04:34 +02:00
|
|
|
// Shorten the way if the mask is a vector of constants.
|
2020-08-10 12:05:43 +02:00
|
|
|
// Create a build_vector pattern, with loads/undefs as necessary and then
|
|
|
|
// shuffle blend with the pass through value.
|
2019-08-02 22:04:34 +02:00
|
|
|
if (isConstantIntVector(Mask)) {
|
|
|
|
unsigned MemIndex = 0;
|
2020-08-10 12:05:43 +02:00
|
|
|
VResult = UndefValue::get(VecType);
|
|
|
|
SmallVector<int, 16> ShuffleMask(VectorWidth, UndefMaskElem);
|
2019-08-02 22:04:34 +02:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
2020-08-10 12:05:43 +02:00
|
|
|
Value *InsertElt;
|
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue()) {
|
|
|
|
InsertElt = UndefValue::get(EltTy);
|
|
|
|
ShuffleMask[Idx] = Idx + VectorWidth;
|
|
|
|
} else {
|
|
|
|
Value *NewPtr =
|
|
|
|
Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, MemIndex);
|
|
|
|
InsertElt = Builder.CreateAlignedLoad(EltTy, NewPtr, Align(1),
|
|
|
|
"Load" + Twine(Idx));
|
|
|
|
ShuffleMask[Idx] = Idx;
|
|
|
|
++MemIndex;
|
|
|
|
}
|
|
|
|
VResult = Builder.CreateInsertElement(VResult, InsertElt, Idx,
|
|
|
|
"Res" + Twine(Idx));
|
2019-08-02 22:04:34 +02:00
|
|
|
}
|
2020-08-10 12:05:43 +02:00
|
|
|
VResult = Builder.CreateShuffleVector(VResult, PassThru, ShuffleMask);
|
2019-08-02 22:04:34 +02:00
|
|
|
CI->replaceAllUsesWith(VResult);
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-03 01:43:53 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2019-03-21 18:38:52 +01:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
|
|
|
// %res.phi.else3 = phi <16 x i32> [ %11, %cond.load1 ], [ %res.phi.else, %else ]
|
|
|
|
// %mask_1 = extractelement <16 x i1> %mask, i32 Idx
|
|
|
|
// br i1 %mask_1, label %cond.load, label %else
|
|
|
|
//
|
|
|
|
|
2019-08-03 01:43:53 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-03 01:43:53 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx, "Mask" + Twine(Idx));
|
|
|
|
}
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
|
|
|
// %EltAddr = getelementptr i32* %1, i32 0
|
|
|
|
// %Elt = load i32* %EltAddr
|
|
|
|
// VResult = insertelement <16 x i32> VResult, i32 %Elt, i32 Idx
|
|
|
|
//
|
2021-01-28 20:39:19 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2021-01-28 20:39:19 +01:00
|
|
|
|
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.load");
|
2019-03-21 18:38:52 +01:00
|
|
|
|
2021-01-28 20:39:19 +01:00
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2020-01-23 11:33:12 +01:00
|
|
|
LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Ptr, Align(1));
|
2019-03-21 18:38:52 +01:00
|
|
|
Value *NewVResult = Builder.CreateInsertElement(VResult, Load, Idx);
|
|
|
|
|
|
|
|
// Move the pointer if there are more blocks to come.
|
|
|
|
Value *NewPtr;
|
|
|
|
if ((Idx + 1) != VectorWidth)
|
|
|
|
NewPtr = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, 1);
|
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 20:39:19 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
2019-03-21 18:38:52 +01:00
|
|
|
BasicBlock *PrevIfBlock = IfBlock;
|
|
|
|
IfBlock = NewIfBlock;
|
|
|
|
|
|
|
|
// Create the phi to join the new and previous value.
|
2021-01-28 20:39:19 +01:00
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
2019-03-21 18:38:52 +01:00
|
|
|
PHINode *ResultPhi = Builder.CreatePHI(VecType, 2, "res.phi.else");
|
|
|
|
ResultPhi->addIncoming(NewVResult, CondBlock);
|
|
|
|
ResultPhi->addIncoming(VResult, PrevIfBlock);
|
|
|
|
VResult = ResultPhi;
|
|
|
|
|
|
|
|
// Add a PHI for the pointer if this isn't the last iteration.
|
|
|
|
if ((Idx + 1) != VectorWidth) {
|
|
|
|
PHINode *PtrPhi = Builder.CreatePHI(Ptr->getType(), 2, "ptr.phi.else");
|
|
|
|
PtrPhi->addIncoming(NewPtr, CondBlock);
|
|
|
|
PtrPhi->addIncoming(Ptr, PrevIfBlock);
|
|
|
|
Ptr = PtrPhi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CI->replaceAllUsesWith(VResult);
|
|
|
|
CI->eraseFromParent();
|
|
|
|
|
|
|
|
ModifiedDT = true;
|
|
|
|
}
|
|
|
|
|
2021-02-11 09:59:52 +01:00
|
|
|
static void scalarizeMaskedCompressStore(const DataLayout &DL, CallInst *CI,
|
|
|
|
DomTreeUpdater *DTU,
|
2021-01-28 16:13:17 +01:00
|
|
|
bool &ModifiedDT) {
|
2019-03-21 18:38:52 +01:00
|
|
|
Value *Src = CI->getArgOperand(0);
|
|
|
|
Value *Ptr = CI->getArgOperand(1);
|
|
|
|
Value *Mask = CI->getArgOperand(2);
|
|
|
|
|
2020-07-09 20:51:03 +02:00
|
|
|
auto *VecType = cast<FixedVectorType>(Src->getType());
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
IRBuilder<> Builder(CI->getContext());
|
|
|
|
Instruction *InsertPt = CI;
|
|
|
|
BasicBlock *IfBlock = CI->getParent();
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(InsertPt);
|
|
|
|
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
|
|
|
|
2020-04-10 23:23:20 +02:00
|
|
|
Type *EltTy = VecType->getElementType();
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
unsigned VectorWidth = VecType->getNumElements();
|
|
|
|
|
2019-08-02 22:04:34 +02:00
|
|
|
// Shorten the way if the mask is a vector of constants.
|
|
|
|
if (isConstantIntVector(Mask)) {
|
|
|
|
unsigned MemIndex = 0;
|
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
if (cast<Constant>(Mask)->getAggregateElement(Idx)->isNullValue())
|
|
|
|
continue;
|
|
|
|
Value *OneElt =
|
|
|
|
Builder.CreateExtractElement(Src, Idx, "Elt" + Twine(Idx));
|
|
|
|
Value *NewPtr = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, MemIndex);
|
2020-01-23 16:18:34 +01:00
|
|
|
Builder.CreateAlignedStore(OneElt, NewPtr, Align(1));
|
2019-08-02 22:04:34 +02:00
|
|
|
++MemIndex;
|
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-03 01:43:53 +02:00
|
|
|
// If the mask is not v1i1, use scalar bit test operations. This generates
|
|
|
|
// better results on X86 at least.
|
|
|
|
Value *SclrMask;
|
|
|
|
if (VectorWidth != 1) {
|
|
|
|
Type *SclrMaskTy = Builder.getIntNTy(VectorWidth);
|
|
|
|
SclrMask = Builder.CreateBitCast(Mask, SclrMaskTy, "scalar_mask");
|
|
|
|
}
|
|
|
|
|
2019-03-21 18:38:52 +01:00
|
|
|
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
|
|
|
|
// Fill the "else" block, created in the previous iteration
|
|
|
|
//
|
|
|
|
// %mask_1 = extractelement <16 x i1> %mask, i32 Idx
|
|
|
|
// br i1 %mask_1, label %cond.store, label %else
|
|
|
|
//
|
2019-08-03 01:43:53 +02:00
|
|
|
Value *Predicate;
|
|
|
|
if (VectorWidth != 1) {
|
2021-02-11 09:59:52 +01:00
|
|
|
Value *Mask = Builder.getInt(APInt::getOneBitSet(
|
|
|
|
VectorWidth, adjustForEndian(DL, VectorWidth, Idx)));
|
2019-08-03 01:43:53 +02:00
|
|
|
Predicate = Builder.CreateICmpNE(Builder.CreateAnd(SclrMask, Mask),
|
|
|
|
Builder.getIntN(VectorWidth, 0));
|
|
|
|
} else {
|
|
|
|
Predicate = Builder.CreateExtractElement(Mask, Idx, "Mask" + Twine(Idx));
|
|
|
|
}
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
// Create "cond" block
|
|
|
|
//
|
|
|
|
// %OneElt = extractelement <16 x i32> %Src, i32 Idx
|
|
|
|
// %EltAddr = getelementptr i32* %1, i32 0
|
|
|
|
// %store i32 %OneElt, i32* %EltAddr
|
|
|
|
//
|
2021-01-28 20:59:15 +01:00
|
|
|
Instruction *ThenTerm =
|
2021-01-28 16:13:17 +01:00
|
|
|
SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
|
|
|
|
/*BranchWeights=*/nullptr, DTU);
|
2021-01-28 20:59:15 +01:00
|
|
|
|
|
|
|
BasicBlock *CondBlock = ThenTerm->getParent();
|
|
|
|
CondBlock->setName("cond.store");
|
2019-03-21 18:38:52 +01:00
|
|
|
|
2021-01-28 20:59:15 +01:00
|
|
|
Builder.SetInsertPoint(CondBlock->getTerminator());
|
2019-03-21 18:38:52 +01:00
|
|
|
Value *OneElt = Builder.CreateExtractElement(Src, Idx);
|
2020-01-23 16:18:34 +01:00
|
|
|
Builder.CreateAlignedStore(OneElt, Ptr, Align(1));
|
2019-03-21 18:38:52 +01:00
|
|
|
|
|
|
|
// Move the pointer if there are more blocks to come.
|
|
|
|
Value *NewPtr;
|
|
|
|
if ((Idx + 1) != VectorWidth)
|
|
|
|
NewPtr = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, 1);
|
|
|
|
|
|
|
|
// Create "else" block, fill it in the next iteration
|
2021-01-28 20:59:15 +01:00
|
|
|
BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
|
|
|
|
NewIfBlock->setName("else");
|
2019-03-21 18:38:52 +01:00
|
|
|
BasicBlock *PrevIfBlock = IfBlock;
|
|
|
|
IfBlock = NewIfBlock;
|
|
|
|
|
2021-01-28 20:59:15 +01:00
|
|
|
Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
|
|
|
|
|
2019-03-21 18:38:52 +01:00
|
|
|
// Add a PHI for the pointer if this isn't the last iteration.
|
|
|
|
if ((Idx + 1) != VectorWidth) {
|
|
|
|
PHINode *PtrPhi = Builder.CreatePHI(Ptr->getType(), 2, "ptr.phi.else");
|
|
|
|
PtrPhi->addIncoming(NewPtr, CondBlock);
|
|
|
|
PtrPhi->addIncoming(Ptr, PrevIfBlock);
|
|
|
|
Ptr = PtrPhi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CI->eraseFromParent();
|
|
|
|
|
|
|
|
ModifiedDT = true;
|
|
|
|
}
|
|
|
|
|
2021-01-28 16:13:17 +01:00
|
|
|
static bool runImpl(Function &F, const TargetTransformInfo &TTI,
|
|
|
|
DominatorTree *DT) {
|
|
|
|
Optional<DomTreeUpdater> DTU;
|
|
|
|
if (DT)
|
|
|
|
DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
bool EverMadeChange = false;
|
|
|
|
bool MadeChange = true;
|
2020-12-07 04:51:23 +01:00
|
|
|
auto &DL = F.getParent()->getDataLayout();
|
2017-05-15 13:30:54 +02:00
|
|
|
while (MadeChange) {
|
|
|
|
MadeChange = false;
|
|
|
|
for (Function::iterator I = F.begin(); I != F.end();) {
|
|
|
|
BasicBlock *BB = &*I++;
|
|
|
|
bool ModifiedDTOnIteration = false;
|
2021-01-28 16:13:17 +01:00
|
|
|
MadeChange |= optimizeBlock(*BB, ModifiedDTOnIteration, TTI, DL,
|
|
|
|
DTU.hasValue() ? DTU.getPointer() : nullptr);
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
|
|
|
|
// Restart BB iteration if the dominator tree of the Function was changed
|
|
|
|
if (ModifiedDTOnIteration)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
EverMadeChange |= MadeChange;
|
|
|
|
}
|
|
|
|
return EverMadeChange;
|
|
|
|
}
|
|
|
|
|
2020-12-07 04:51:23 +01:00
|
|
|
bool ScalarizeMaskedMemIntrinLegacyPass::runOnFunction(Function &F) {
|
|
|
|
auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
2021-01-28 16:13:17 +01:00
|
|
|
DominatorTree *DT = nullptr;
|
|
|
|
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
|
|
|
|
DT = &DTWP->getDomTree();
|
|
|
|
return runImpl(F, TTI, DT);
|
2020-12-07 04:51:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
|
|
|
ScalarizeMaskedMemIntrinPass::run(Function &F, FunctionAnalysisManager &AM) {
|
|
|
|
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
|
2021-01-28 16:13:17 +01:00
|
|
|
auto *DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
|
|
|
|
if (!runImpl(F, TTI, DT))
|
2020-12-07 04:51:23 +01:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
PreservedAnalyses PA;
|
|
|
|
PA.preserve<TargetIRAnalysis>();
|
2021-01-28 16:13:17 +01:00
|
|
|
PA.preserve<DominatorTreeAnalysis>();
|
2020-12-07 04:51:23 +01:00
|
|
|
return PA;
|
|
|
|
}
|
|
|
|
|
2020-12-03 17:43:30 +01:00
|
|
|
static bool optimizeBlock(BasicBlock &BB, bool &ModifiedDT,
|
2021-01-28 16:13:17 +01:00
|
|
|
const TargetTransformInfo &TTI, const DataLayout &DL,
|
|
|
|
DomTreeUpdater *DTU) {
|
2017-05-15 13:30:54 +02:00
|
|
|
bool MadeChange = false;
|
|
|
|
|
|
|
|
BasicBlock::iterator CurInstIterator = BB.begin();
|
|
|
|
while (CurInstIterator != BB.end()) {
|
|
|
|
if (CallInst *CI = dyn_cast<CallInst>(&*CurInstIterator++))
|
2021-01-28 16:13:17 +01:00
|
|
|
MadeChange |= optimizeCallInst(CI, ModifiedDT, TTI, DL, DTU);
|
2017-05-15 13:30:54 +02:00
|
|
|
if (ModifiedDT)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
2020-12-03 17:43:30 +01:00
|
|
|
static bool optimizeCallInst(CallInst *CI, bool &ModifiedDT,
|
2020-12-03 20:02:47 +01:00
|
|
|
const TargetTransformInfo &TTI,
|
2021-01-28 16:13:17 +01:00
|
|
|
const DataLayout &DL, DomTreeUpdater *DTU) {
|
2017-05-15 13:30:54 +02:00
|
|
|
IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI);
|
|
|
|
if (II) {
|
2020-09-08 10:08:59 +02:00
|
|
|
// The scalarization code below does not work for scalable vectors.
|
|
|
|
if (isa<ScalableVectorType>(II->getType()) ||
|
|
|
|
any_of(II->arg_operands(),
|
|
|
|
[](Value *V) { return isa<ScalableVectorType>(V->getType()); }))
|
|
|
|
return false;
|
|
|
|
|
2017-05-15 13:30:54 +02:00
|
|
|
switch (II->getIntrinsicID()) {
|
|
|
|
default:
|
|
|
|
break;
|
2020-01-21 16:13:04 +01:00
|
|
|
case Intrinsic::masked_load:
|
2017-05-15 13:30:54 +02:00
|
|
|
// Scalarize unsupported vector masked load
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedLoad(
|
2020-01-21 16:13:04 +01:00
|
|
|
CI->getType(),
|
|
|
|
cast<ConstantInt>(CI->getArgOperand(1))->getAlignValue()))
|
2019-03-21 06:54:37 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedLoad(DL, CI, DTU, ModifiedDT);
|
2019-03-21 06:54:37 +01:00
|
|
|
return true;
|
2020-01-21 16:13:04 +01:00
|
|
|
case Intrinsic::masked_store:
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedStore(
|
2020-01-21 16:13:04 +01:00
|
|
|
CI->getArgOperand(0)->getType(),
|
|
|
|
cast<ConstantInt>(CI->getArgOperand(2))->getAlignValue()))
|
2019-03-21 06:54:37 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedStore(DL, CI, DTU, ModifiedDT);
|
2019-03-21 06:54:37 +01:00
|
|
|
return true;
|
2020-01-21 16:13:04 +01:00
|
|
|
case Intrinsic::masked_gather: {
|
2021-07-02 02:08:23 +02:00
|
|
|
MaybeAlign MA =
|
|
|
|
cast<ConstantInt>(CI->getArgOperand(1))->getMaybeAlignValue();
|
2020-05-19 04:16:06 +02:00
|
|
|
Type *LoadTy = CI->getType();
|
2021-07-02 02:08:23 +02:00
|
|
|
Align Alignment = DL.getValueOrABITypeAlignment(MA,
|
|
|
|
LoadTy->getScalarType());
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedGather(LoadTy, Alignment))
|
2019-03-21 06:54:37 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedGather(DL, CI, DTU, ModifiedDT);
|
2019-03-21 06:54:37 +01:00
|
|
|
return true;
|
2020-01-21 16:13:04 +01:00
|
|
|
}
|
|
|
|
case Intrinsic::masked_scatter: {
|
2021-07-02 02:08:23 +02:00
|
|
|
MaybeAlign MA =
|
|
|
|
cast<ConstantInt>(CI->getArgOperand(2))->getMaybeAlignValue();
|
2020-05-19 04:16:06 +02:00
|
|
|
Type *StoreTy = CI->getArgOperand(0)->getType();
|
2021-07-02 02:08:23 +02:00
|
|
|
Align Alignment = DL.getValueOrABITypeAlignment(MA,
|
|
|
|
StoreTy->getScalarType());
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedScatter(StoreTy, Alignment))
|
2019-03-21 06:54:37 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedScatter(DL, CI, DTU, ModifiedDT);
|
2019-03-21 06:54:37 +01:00
|
|
|
return true;
|
2020-01-21 16:13:04 +01:00
|
|
|
}
|
2019-03-21 18:38:52 +01:00
|
|
|
case Intrinsic::masked_expandload:
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedExpandLoad(CI->getType()))
|
2019-03-21 18:38:52 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedExpandLoad(DL, CI, DTU, ModifiedDT);
|
2019-03-21 18:38:52 +01:00
|
|
|
return true;
|
|
|
|
case Intrinsic::masked_compressstore:
|
2020-12-03 20:02:47 +01:00
|
|
|
if (TTI.isLegalMaskedCompressStore(CI->getArgOperand(0)->getType()))
|
2019-03-21 18:38:52 +01:00
|
|
|
return false;
|
2021-02-11 09:59:52 +01:00
|
|
|
scalarizeMaskedCompressStore(DL, CI, DTU, ModifiedDT);
|
2019-03-21 18:38:52 +01:00
|
|
|
return true;
|
2017-05-15 13:30:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|