1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00

[InstCombine] simplify masked store intrinsics with all ones or zeros masks

A masked store with a zero mask means there's no store.
A masked store with an allOnes mask means it's a normal vector store.

This is a continuation of:
http://reviews.llvm.org/rL259369

llvm-svn: 259392
This commit is contained in:
Sanjay Patel 2016-02-01 19:39:52 +00:00
parent bd28c13e3a
commit 0a594deff4
2 changed files with 39 additions and 1 deletions

View File

@ -773,6 +773,25 @@ static Value *simplifyMaskedLoad(const IntrinsicInst &II,
return nullptr;
}
static Instruction *simplifyMaskedStore(IntrinsicInst &II, InstCombiner &IC) {
auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(3));
if (!ConstMask)
return nullptr;
// If the mask is all zeros, this instruction does nothing.
if (ConstMask->isNullValue())
return IC.EraseInstFromFunction(II);
// If the mask is all ones, this is a plain vector store of the 1st argument.
if (ConstMask->isAllOnesValue()) {
Value *StorePtr = II.getArgOperand(1);
unsigned Alignment = cast<ConstantInt>(II.getArgOperand(2))->getZExtValue();
return new StoreInst(II.getArgOperand(0), StorePtr, false, Alignment);
}
return nullptr;
}
/// CallInst simplification. This mostly only handles folding of intrinsic
/// instructions. For normal calls, it allows visitCallSite to do the heavy
/// lifting.
@ -901,9 +920,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (Value *SimplifiedMaskedOp = simplifyMaskedLoad(*II, *Builder))
return ReplaceInstUsesWith(CI, SimplifiedMaskedOp);
break;
case Intrinsic::masked_store:
return simplifyMaskedStore(*II, *this);
// TODO: Handle the other masked ops.
// case Intrinsic::masked_store:
// case Intrinsic::masked_gather:
// case Intrinsic::masked_scatter:

View File

@ -1,6 +1,7 @@
; RUN: opt -instcombine -S < %s | FileCheck %s
declare <2 x double> @llvm.masked.load.v2f64(<2 x double>* %ptrs, i32, <2 x i1> %mask, <2 x double> %src0)
declare void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptrs, i32, <2 x i1> %mask)
define <2 x double> @load_zeromask(<2 x double>* %ptr, <2 x double> %passthru) {
@ -20,3 +21,20 @@ define <2 x double> @load_onemask(<2 x double>* %ptr, <2 x double> %passthru) {
; CHECK-NEXT: ret <2 x double> %unmaskedload
}
define void @store_zeromask(<2 x double>* %ptr, <2 x double> %val) {
call void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptr, i32 3, <2 x i1> zeroinitializer)
ret void
; CHECK-LABEL: @store_zeromask(
; CHECK-NEXT: ret void
}
define void @store_onemask(<2 x double>* %ptr, <2 x double> %val) {
call void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptr, i32 4, <2 x i1> <i1 1, i1 1>)
ret void
; CHECK-LABEL: @store_onemask(
; CHECK-NEXT: store <2 x double> %val, <2 x double>* %ptr, align 4
; CHECK-NEXT: ret void
}