[llvm] 0a241e9 - [NFC][InstCombine] `vector_reduce_xor(?ext(<n x i1>))` --> `?ext(vector_reduce_add(<n x i1>))`
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 7 07:33:13 PDT 2021
Author: Roman Lebedev
Date: 2021-08-07T17:31:33+03:00
New Revision: 0a241e90d4931a764109da70c2322a0a9386b1a7
URL: https://github.com/llvm/llvm-project/commit/0a241e90d4931a764109da70c2322a0a9386b1a7
DIFF: https://github.com/llvm/llvm-project/commit/0a241e90d4931a764109da70c2322a0a9386b1a7.diff
LOG: [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)
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 2ba326d791c2..210652e23377 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -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());
More information about the llvm-commits
mailing list