forked from OSchip/llvm-project
[NFC][InstCombine] `vector_reduce_xor(?ext(<n x i1>))` --> `?ext(vector_reduce_add(<n x i1>))`
Instead of expanding it ourselves, we can just forward to `?ext(vector_reduce_add(<n x i1>))`, as per alive2: https://alive2.llvm.org/ce/z/ymz7zE (self) https://alive2.llvm.org/ce/z/eKu2v2 (skipped zext) https://alive2.llvm.org/ce/z/c3BXgc (skipped sext)
This commit is contained in:
parent
c6ff867f92
commit
0a241e90d4
|
@ -2038,20 +2038,17 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
|
|||
if (IID == Intrinsic::vector_reduce_xor) {
|
||||
// Exclusive disjunction reduction over the vector with
|
||||
// (potentially-extended) i1 element type is actually a
|
||||
// (potentially-extended) parity check:
|
||||
// (potentially-extended) arithmetic `add` reduction over the original
|
||||
// non-extended value:
|
||||
// vector_reduce_xor(?ext(<n x i1>))
|
||||
// -->
|
||||
// ?ext(trunc(vector_reduce_and(<n x i1>) to i1))
|
||||
// ?ext(vector_reduce_add(<n x i1>))
|
||||
Value *Arg = II->getArgOperand(0);
|
||||
Value *Vect;
|
||||
if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
|
||||
if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
|
||||
if (FTy->getElementType() == Builder.getInt1Ty()) {
|
||||
Value *V = Builder.CreateBitCast(
|
||||
Vect, Builder.getIntNTy(FTy->getNumElements()));
|
||||
Value *Res = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, V);
|
||||
Res = Builder.CreateTrunc(Res,
|
||||
IntegerType::get(Res->getContext(), 1));
|
||||
Value *Res = Builder.CreateAddReduce(Vect);
|
||||
if (Arg != Vect)
|
||||
Res = Builder.CreateCast(cast<CastInst>(Arg)->getOpcode(), Res,
|
||||
II->getType());
|
||||
|
|
Loading…
Reference in New Issue