@@ -798,10 +798,31 @@ instCombineConvertFromSVBool(InstCombiner &IC, IntrinsicInst &II) {
798
798
return IC.replaceInstUsesWith (II, EarliestReplacement);
799
799
}
800
800
801
+ static bool isAllActivePredicate (Value *Pred) {
802
+ // Look through convert.from.svbool(convert.to.svbool(...) chain.
803
+ Value *UncastedPred;
804
+ if (match (Pred, m_Intrinsic<Intrinsic::aarch64_sve_convert_from_svbool>(
805
+ m_Intrinsic<Intrinsic::aarch64_sve_convert_to_svbool>(
806
+ m_Value (UncastedPred)))))
807
+ // If the predicate has the same or less lanes than the uncasted
808
+ // predicate then we know the casting has no effect.
809
+ if (cast<ScalableVectorType>(Pred->getType ())->getMinNumElements () <=
810
+ cast<ScalableVectorType>(UncastedPred->getType ())->getMinNumElements ())
811
+ Pred = UncastedPred;
812
+
813
+ return match (Pred, m_Intrinsic<Intrinsic::aarch64_sve_ptrue>(
814
+ m_ConstantInt<AArch64SVEPredPattern::all>()));
815
+ }
816
+
801
817
static std::optional<Instruction *> instCombineSVESel (InstCombiner &IC,
802
818
IntrinsicInst &II) {
803
- auto Select = IC.Builder .CreateSelect (II.getOperand (0 ), II.getOperand (1 ),
804
- II.getOperand (2 ));
819
+ // svsel(ptrue, x, y) => x
820
+ auto *OpPredicate = II.getOperand (0 );
821
+ if (isAllActivePredicate (OpPredicate))
822
+ return IC.replaceInstUsesWith (II, II.getOperand (1 ));
823
+
824
+ auto Select =
825
+ IC.Builder .CreateSelect (OpPredicate, II.getOperand (1 ), II.getOperand (2 ));
805
826
return IC.replaceInstUsesWith (II, Select);
806
827
}
807
828
@@ -1200,22 +1221,6 @@ instCombineSVEVectorFuseMulAddSub(InstCombiner &IC, IntrinsicInst &II,
1200
1221
return IC.replaceInstUsesWith (II, Res);
1201
1222
}
1202
1223
1203
- static bool isAllActivePredicate (Value *Pred) {
1204
- // Look through convert.from.svbool(convert.to.svbool(...) chain.
1205
- Value *UncastedPred;
1206
- if (match (Pred, m_Intrinsic<Intrinsic::aarch64_sve_convert_from_svbool>(
1207
- m_Intrinsic<Intrinsic::aarch64_sve_convert_to_svbool>(
1208
- m_Value (UncastedPred)))))
1209
- // If the predicate has the same or less lanes than the uncasted
1210
- // predicate then we know the casting has no effect.
1211
- if (cast<ScalableVectorType>(Pred->getType ())->getMinNumElements () <=
1212
- cast<ScalableVectorType>(UncastedPred->getType ())->getMinNumElements ())
1213
- Pred = UncastedPred;
1214
-
1215
- return match (Pred, m_Intrinsic<Intrinsic::aarch64_sve_ptrue>(
1216
- m_ConstantInt<AArch64SVEPredPattern::all>()));
1217
- }
1218
-
1219
1224
static std::optional<Instruction *>
1220
1225
instCombineSVELD1 (InstCombiner &IC, IntrinsicInst &II, const DataLayout &DL) {
1221
1226
Value *Pred = II.getOperand (0 );
0 commit comments