diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-04-28 18:32:24 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:46:42 +0000 | 
| commit | 3a9a9c0ca44ec535dcf73fe8462bee458e54814b (patch) | |
| tree | 13eff4cf89a999893d2f6ead8c5b4684236df8ed /contrib/llvm-project/llvm/lib/Transforms | |
| parent | 53683b95ef66a12337999587cd98302b1b425920 (diff) | |
| parent | 139d5007613696147437159a7f0d0cdcac702529 (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms')
4 files changed, 44 insertions, 24 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 6bbb0251f2bc..2aab79e89078 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1961,6 +1961,12 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {        }      } +    // If this 'and' clears the sign-bits added by ashr, replace with lshr: +    // and (ashr X, ShiftC), C --> lshr X, ShiftC +    if (match(Op0, m_AShr(m_Value(X), m_APInt(ShiftC))) && ShiftC->ult(Width) && +        C->isMask(Width - ShiftC->getZExtValue())) +      return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, *ShiftC)); +      const APInt *AddC;      if (match(Op0, m_Add(m_Value(X), m_APInt(AddC)))) {        // If we add zeros to every bit below a mask, the add has no effect: diff --git a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 65e60498ff95..881b00f2a55a 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1572,6 +1572,23 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,      }    } +  // Canonicalize a signbit condition to use zero constant by swapping: +  // (CmpLHS > -1) ? TV : FV --> (CmpLHS < 0) ? FV : TV +  // To avoid conflicts (infinite loops) with other canonicalizations, this is +  // not applied with any constant select arm. +  if (Pred == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes()) && +      !match(TrueVal, m_Constant()) && !match(FalseVal, m_Constant()) && +      ICI->hasOneUse()) { +    InstCombiner::BuilderTy::InsertPointGuard Guard(Builder); +    Builder.SetInsertPoint(&SI); +    Value *IsNeg = Builder.CreateICmpSLT( +        CmpLHS, ConstantInt::getNullValue(CmpLHS->getType()), ICI->getName()); +    replaceOperand(SI, 0, IsNeg); +    SI.swapValues(); +    SI.swapProfMetadata(); +    return &SI; +  } +    // FIXME: This code is nearly duplicated in InstSimplify. Using/refactoring    // decomposeBitTestICmp() might help.    { diff --git a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 21c16f07e237..46ff0994e04e 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2544,19 +2544,18 @@ void InnerLoopVectorizer::widenIntOrFpInduction(      Type *ScalarTy = IntegerType::get(ScalarIV->getContext(),                                        Step->getType()->getScalarSizeInBits()); -    Instruction::BinaryOps IncOp = ID.getInductionOpcode(); -    if (IncOp == Instruction::BinaryOpsEnd) -      IncOp = Instruction::Add;      for (unsigned Part = 0; Part < UF; ++Part) {        Value *StartIdx = ConstantInt::get(ScalarTy, Part); -      Instruction::BinaryOps MulOp = Instruction::Mul; +      Value *EntryPart;        if (Step->getType()->isFloatingPointTy()) {          StartIdx = Builder.CreateUIToFP(StartIdx, Step->getType()); -        MulOp = Instruction::FMul; +        Value *MulOp = Builder.CreateFMul(StartIdx, Step); +        EntryPart = Builder.CreateBinOp(ID.getInductionOpcode(), ScalarIV, +                                        MulOp, "induction"); +      } else { +        EntryPart = Builder.CreateAdd( +            ScalarIV, Builder.CreateMul(StartIdx, Step), "induction");        } - -      Value *Mul = Builder.CreateBinOp(MulOp, StartIdx, Step); -      Value *EntryPart = Builder.CreateBinOp(IncOp, ScalarIV, Mul, "induction");        State.set(Def, EntryPart, Part);        if (Trunc) {          assert(!Step->getType()->isFloatingPointTy() && @@ -6035,6 +6034,18 @@ unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF,        !(InterleaveSmallLoopScalarReduction && HasReductions && VF.isScalar()))      return 1; +  // If we did not calculate the cost for VF (because the user selected the VF) +  // then we calculate the cost of VF here. +  if (LoopCost == 0) { +    InstructionCost C = expectedCost(VF).first; +    assert(C.isValid() && "Expected to have chosen a VF with valid cost"); +    LoopCost = *C.getValue(); + +    // Loop body is free and there is no need for interleaving. +    if (LoopCost == 0) +      return 1; +  } +    RegisterUsage R = calculateRegisterUsage({VF})[0];    // We divide by these constants so assume that we have at least one    // instruction that uses at least one register. @@ -6126,16 +6137,6 @@ unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF,    assert(IC > 0 && "Interleave count must be greater than 0."); -  // If we did not calculate the cost for VF (because the user selected the VF) -  // then we calculate the cost of VF here. -  if (LoopCost == 0) { -    InstructionCost C = expectedCost(VF).first; -    assert(C.isValid() && "Expected to have chosen a VF with valid cost"); -    LoopCost = *C.getValue(); -  } - -  assert(LoopCost && "Non-zero loop cost expected"); -    // Interleave if we vectorized this loop and there is a reduction that could    // benefit from interleaving.    if (VF.isVector() && HasReductions) { diff --git a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 620d388199e0..258f6c67e54d 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -152,12 +152,7 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {    Value *SrcPtr = Load->getPointerOperand()->stripPointerCasts();    assert(isa<PointerType>(SrcPtr->getType()) && "Expected a pointer type"); -  // If original AS != Load's AS, we can't bitcast the original pointer and have -  // to use Load's operand instead. Ideally we would want to strip pointer casts -  // without changing AS, but there's no API to do that ATM.    unsigned AS = Load->getPointerAddressSpace(); -  if (AS != SrcPtr->getType()->getPointerAddressSpace()) -    SrcPtr = Load->getPointerOperand();    // We are potentially transforming byte-sized (8-bit) memory accesses, so make    // sure we have all of our type-based constraints in place for this target. @@ -245,7 +240,8 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {    // It is safe and potentially profitable to load a vector directly:    // inselt undef, load Scalar, 0 --> load VecPtr    IRBuilder<> Builder(Load); -  Value *CastedPtr = Builder.CreateBitCast(SrcPtr, MinVecTy->getPointerTo(AS)); +  Value *CastedPtr = Builder.CreatePointerBitCastOrAddrSpaceCast( +      SrcPtr, MinVecTy->getPointerTo(AS));    Value *VecLd = Builder.CreateAlignedLoad(MinVecTy, CastedPtr, Alignment);    VecLd = Builder.CreateShuffleVector(VecLd, Mask);  | 
