llvm.org GIT mirror llvm / fb0402e
[InstCombine] reduce code duplication; NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360051 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 5 months ago
1 changed file(s) with 19 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
19621962 return SimplifyDemandedVectorElts(Op, DemandedElts, UndefElts);
19631963 };
19641964
1965 switch (II->getIntrinsicID()) {
1965 Intrinsic::ID IID = II->getIntrinsicID();
1966 switch (IID) {
19661967 default: break;
19671968 case Intrinsic::objectsize:
19681969 if (Value *V = lowerObjectSizeCall(II, DL, &TLI, /*MustSucceed=*/false))
20452046 // Canonicalize funnel shift right by constant to funnel shift left. This
20462047 // is not entirely arbitrary. For historical reasons, the backend may
20472048 // recognize rotate left patterns but miss rotate right patterns.
2048 if (II->getIntrinsicID() == Intrinsic::fshr) {
2049 if (IID == Intrinsic::fshr) {
20492050 // fshr X, Y, C --> fshl X, Y, (BitWidth - C)
20502051 Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC);
20512052 Module *Mod = II->getModule();
20522053 Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty);
20532054 return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC });
20542055 }
2055 assert(II->getIntrinsicID() == Intrinsic::fshl &&
2056 assert(IID == Intrinsic::fshl &&
20562057 "All funnel shifts by simple constants should go left");
20572058
20582059 // fshl(X, 0, C) --> shl X, C
20962097 const APInt *C0, *C1;
20972098 Value *Arg0 = II->getArgOperand(0);
20982099 Value *Arg1 = II->getArgOperand(1);
2099 bool IsSigned = II->getIntrinsicID() == Intrinsic::sadd_with_overflow;
2100 bool IsSigned = IID == Intrinsic::sadd_with_overflow;
21002101 bool HasNWAdd = IsSigned ? match(Arg0, m_NSWAdd(m_Value(X), m_APInt(C0)))
21012102 : match(Arg0, m_NUWAdd(m_Value(X), m_APInt(C0)));
21022103 if (HasNWAdd && match(Arg1, m_APInt(C1))) {
21062107 if (!Overflow)
21072108 return replaceInstUsesWith(
21082109 *II, Builder.CreateBinaryIntrinsic(
2109 II->getIntrinsicID(), X,
2110 ConstantInt::get(Arg1->getType(), NewC)));
2110 IID, X, ConstantInt::get(Arg1->getType(), NewC)));
21112111 }
21122112 break;
21132113 }
21552155 case Intrinsic::ssub_sat: {
21562156 Value *Arg0 = II->getArgOperand(0);
21572157 Value *Arg1 = II->getArgOperand(1);
2158 Intrinsic::ID IID = II->getIntrinsicID();
21592158
21602159 // Make use of known overflow information.
21612160 OverflowResult OR;
22072206 APInt NewVal;
22082207 bool IsUnsigned =
22092208 IID == Intrinsic::uadd_sat || IID == Intrinsic::usub_sat;
2210 if (Other->getIntrinsicID() == II->getIntrinsicID() &&
2209 if (Other->getIntrinsicID() == IID &&
22112210 match(Arg1, m_APInt(Val)) &&
22122211 match(Other->getArgOperand(0), m_Value(X)) &&
22132212 match(Other->getArgOperand(1), m_APInt(Val2))) {
22422241 return I;
22432242 Value *Arg0 = II->getArgOperand(0);
22442243 Value *Arg1 = II->getArgOperand(1);
2245 Intrinsic::ID IID = II->getIntrinsicID();
22462244 Value *X, *Y;
22472245 if (match(Arg0, m_FNeg(m_Value(X))) && match(Arg1, m_FNeg(m_Value(Y))) &&
22482246 (Arg0->hasOneUse() || Arg1->hasOneUse())) {
23722370 Value *ExtSrc;
23732371 if (match(II->getArgOperand(0), m_OneUse(m_FPExt(m_Value(ExtSrc))))) {
23742372 // Narrow the call: intrinsic (fpext x) -> fpext (intrinsic x)
2375 Value *NarrowII =
2376 Builder.CreateUnaryIntrinsic(II->getIntrinsicID(), ExtSrc, II);
2373 Value *NarrowII = Builder.CreateUnaryIntrinsic(IID, ExtSrc, II);
23772374 return new FPExtInst(NarrowII, II->getType());
23782375 }
23792376 break;
27262723 Value *Arg1 = II->getArgOperand(1);
27272724
27282725 Value *V;
2729 switch (II->getIntrinsicID()) {
2726 switch (IID) {
27302727 default: llvm_unreachable("Case stmts out of sync!");
27312728 case Intrinsic::x86_avx512_add_ps_512:
27322729 case Intrinsic::x86_avx512_add_pd_512:
27702767 Value *RHS = Builder.CreateExtractElement(Arg1, (uint64_t)0);
27712768
27722769 Value *V;
2773 switch (II->getIntrinsicID()) {
2770 switch (IID) {
27742771 default: llvm_unreachable("Case stmts out of sync!");
27752772 case Intrinsic::x86_avx512_mask_add_ss_round:
27762773 case Intrinsic::x86_avx512_mask_add_sd_round:
33623359 }
33633360
33643361 // Check for constant LHS & RHS - in this case we just simplify.
3365 bool Zext = (II->getIntrinsicID() == Intrinsic::arm_neon_vmullu ||
3366 II->getIntrinsicID() == Intrinsic::aarch64_neon_umull);
3362 bool Zext = (IID == Intrinsic::arm_neon_vmullu ||
3363 IID == Intrinsic::aarch64_neon_umull);
33673364 VectorType *NewVT = cast(II->getType());
33683365 if (Constant *CV0 = dyn_cast(Arg0)) {
33693366 if (Constant *CV1 = dyn_cast(Arg1)) {
34403437 APFloat Significand = frexp(C->getValueAPF(), Exp,
34413438 APFloat::rmNearestTiesToEven);
34423439
3443 if (II->getIntrinsicID() == Intrinsic::amdgcn_frexp_mant) {
3440 if (IID == Intrinsic::amdgcn_frexp_mant) {
34443441 return replaceInstUsesWith(CI, ConstantFP::get(II->getContext(),
34453442 Significand));
34463443 }
36253622 }
36263623 }
36273624
3628 bool Signed = II->getIntrinsicID() == Intrinsic::amdgcn_sbfe;
3625 bool Signed = IID == Intrinsic::amdgcn_sbfe;
36293626
36303627 if (!CWidth || !COffset)
36313628 break;
36583655 if (EnBits == 0xf)
36593656 break; // All inputs enabled.
36603657
3661 bool IsCompr = II->getIntrinsicID() == Intrinsic::amdgcn_exp_compr;
3658 bool IsCompr = IID == Intrinsic::amdgcn_exp_compr;
36623659 bool Changed = false;
36633660 for (int I = 0; I < (IsCompr ? 2 : 4); ++I) {
36643661 if ((!IsCompr && (EnBits & (1 << I)) == 0) ||
37463743 const ConstantInt *CC = cast(II->getArgOperand(2));
37473744 // Guard against invalid arguments.
37483745 int64_t CCVal = CC->getZExtValue();
3749 bool IsInteger = II->getIntrinsicID() == Intrinsic::amdgcn_icmp;
3746 bool IsInteger = IID == Intrinsic::amdgcn_icmp;
37503747 if ((IsInteger && (CCVal < CmpInst::FIRST_ICMP_PREDICATE ||
37513748 CCVal > CmpInst::LAST_ICMP_PREDICATE)) ||
37523749 (!IsInteger && (CCVal < CmpInst::FIRST_FCMP_PREDICATE ||
39293926 break;
39303927 }
39313928 if (CallInst *BCI = dyn_cast(BI)) {
3932 if (IntrinsicInst *II = dyn_cast(BCI)) {
3929 if (auto *II2 = dyn_cast(BCI)) {
39333930 // If there is a stackrestore below this one, remove this one.
3934 if (II->getIntrinsicID() == Intrinsic::stackrestore)
3931 if (II2->getIntrinsicID() == Intrinsic::stackrestore)
39353932 return eraseInstFromFunction(CI);
39363933
39373934 // Bail if we cross over an intrinsic with side effects, such as
39383935 // llvm.stacksave, llvm.read_register, or llvm.setjmp.
3939 if (II->mayHaveSideEffects()) {
3936 if (II2->mayHaveSideEffects()) {
39403937 CannotRemove = true;
39413938 break;
39423939 }