diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index e3370d31a0e39..2053fc45698f5 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1577,18 +1577,26 @@ static SVEIntrinsicInfo constructSVEIntrinsicInfo(IntrinsicInst &II) { } static bool isAllActivePredicate(Value *Pred) { - // Look through convert.from.svbool(convert.to.svbool(...) chain. Value *UncastedPred; + + // Look through predicate casts that only remove lanes. if (match(Pred, m_Intrinsic( - m_Intrinsic( - m_Value(UncastedPred))))) - // If the predicate has the same or less lanes than the uncasted - // predicate then we know the casting has no effect. - if (cast(Pred->getType())->getMinNumElements() <= - cast(UncastedPred->getType())->getMinNumElements()) - Pred = UncastedPred; + m_Value(UncastedPred)))) { + auto *OrigPredTy = cast(Pred->getType()); + Pred = UncastedPred; + + if (match(Pred, m_Intrinsic( + m_Value(UncastedPred)))) + // If the predicate has the same or less lanes than the uncasted predicate + // then we know the casting has no effect. + if (OrigPredTy->getMinNumElements() <= + cast(UncastedPred->getType()) + ->getMinNumElements()) + Pred = UncastedPred; + } + auto *C = dyn_cast(Pred); - return (C && C->isAllOnesValue()); + return C && C->isAllOnesValue(); } // Simplify `V` by only considering the operations that affect active lanes. diff --git a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-to-svbool-binops.ll b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-to-svbool-binops.ll index ecedbdb3522db..abe1ed0fa37b8 100644 --- a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-to-svbool-binops.ll +++ b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-to-svbool-binops.ll @@ -124,6 +124,39 @@ define @try_combine_svbool_binop_orr( %a, %t3 } +; Verify predicate cast does not hinder "isAllActive" knowledge. +define @try_combine_svbool_binop_fadd( %a, %b) { +; CHECK-LABEL: @try_combine_svbool_binop_fadd( +; CHECK-NEXT: [[T2:%.*]] = fadd [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: ret [[T2]] +; + %t1 = tail call @llvm.aarch64.sve.convert.from.svbool.nxv8i1( splat (i1 true)) + %t2 = tail call @llvm.aarch64.sve.fadd.nxv8f16( %t1, %a, %b) + ret %t2 +} + +; Verify predicate cast does not hinder "isAllActive" knowledge. +define @try_combine_svbool_binop_fmul( %a, %b) { +; CHECK-LABEL: @try_combine_svbool_binop_fmul( +; CHECK-NEXT: [[T2:%.*]] = fmul [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: ret [[T2]] +; + %t1 = tail call @llvm.aarch64.sve.convert.from.svbool.nxv4i1( splat (i1 true)) + %t2 = tail call @llvm.aarch64.sve.fmul.nxv4f32( %t1, %a, %b) + ret %t2 +} + +; Verify predicate cast does not hinder "isAllActive" knowledge. +define @try_combine_svbool_binop_fsub( %a, %b) { +; CHECK-LABEL: @try_combine_svbool_binop_fsub( +; CHECK-NEXT: [[T2:%.*]] = fsub [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: ret [[T2]] +; + %t1 = tail call @llvm.aarch64.sve.convert.from.svbool.nxv2i1( splat (i1 true)) + %t2 = tail call @llvm.aarch64.sve.fsub.nxv2f64( %t1, %a, %b) + ret %t2 +} + declare @llvm.aarch64.sve.convert.to.svbool.nxv8i1() declare @llvm.aarch64.sve.convert.to.svbool.nxv4i1() declare @llvm.aarch64.sve.convert.to.svbool.nxv2i1()