return nullptr;
}
-static Value *simplifyMaskedLoad(const IntrinsicInst &II,
- InstCombiner::BuilderTy &Builder) {
- auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(2));
+static bool maskIsAllOneOrUndef(Value *Mask) {
+ auto *ConstMask = dyn_cast<Constant>(Mask);
if (!ConstMask)
- return nullptr;
+ return false;
+ if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
+ return true;
+ for (unsigned I = 0, E = ConstMask->getType()->getVectorNumElements(); I != E;
+ ++I) {
+ if (auto *MaskElt = ConstMask->getAggregateElement(I))
+ if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
+ continue;
+ return false;
+ }
+ return true;
+}
- // If the mask is all ones, this is a plain vector load of the 1st argument.
- if (ConstMask->isAllOnesValue()) {
+static Value *simplifyMaskedLoad(const IntrinsicInst &II,
+ InstCombiner::BuilderTy &Builder) {
+ // If the mask is all ones or undefs, this is a plain vector load of the 1st
+ // argument.
+ if (maskIsAllOneOrUndef(II.getArgOperand(2))) {
Value *LoadPtr = II.getArgOperand(0);
unsigned Alignment = cast<ConstantInt>(II.getArgOperand(1))->getZExtValue();
return Builder.CreateAlignedLoad(LoadPtr, Alignment, "unmaskedload");
; CHECK-NEXT: ret <2 x double> %unmaskedload
}
+define <2 x double> @load_undefmask(<2 x double>* %ptr, <2 x double> %passthru) {
+ %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 2, <2 x i1> <i1 1, i1 undef>, <2 x double> %passthru)
+ ret <2 x double> %res
+
+; CHECK-LABEL: @load_undefmask(
+; CHECK-NEXT: %unmaskedload = load <2 x double>, <2 x double>* %ptr, align 2
+; 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.p0v2f64(<2 x double> %val, <2 x double>* %ptr, i32 3, <2 x i1> zeroinitializer)
ret void