From: Sam Parker Date: Wed, 31 Jul 2019 09:34:11 +0000 (+0000) Subject: [NFC][ARMCGP] Use switch in isSupportedValue X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ea07f7c072c10c517cae51e67d84f711f0007ed;p=platform%2Fupstream%2Fllvm.git [NFC][ARMCGP] Use switch in isSupportedValue Use a switch instead of many isa<> while checking for supported values. Also be explicit about which cast instructions are supported; This allows the removal of SIToFP from GenerateSignBits. llvm-svn: 367402 --- diff --git a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp index 2fc5f4a..9c8da29 100644 --- a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp +++ b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp @@ -187,8 +187,7 @@ static bool GenerateSignBits(Value *V) { unsigned Opc = cast(V)->getOpcode(); return Opc == Instruction::AShr || Opc == Instruction::SDiv || - Opc == Instruction::SRem || Opc == Instruction::SExt || - Opc == Instruction::SIToFP; + Opc == Instruction::SRem || Opc == Instruction::SExt; } static bool EqualTypeSize(Value *V) { @@ -806,54 +805,48 @@ void IRPromoter::Mutate(Type *OrigTy, /// return value is zeroext. We don't allow opcodes that can introduce sign /// bits. bool ARMCodeGenPrepare::isSupportedValue(Value *V) { - if (auto *I = dyn_cast(V)) { - // Now that we allow small types than TypeSize, only allow icmp of - // TypeSize because they will require a trunc to be legalised. - // TODO: Allow icmp of smaller types, and calculate at the end - // whether the transform would be beneficial. - if (isa(I->getOperand(0)->getType())) + if (auto *I = dyn_cast(V)) { + switch (I->getOpcode()) { + default: + return isa(I) && isSupportedType(I) && + !GenerateSignBits(I); + case Instruction::GetElementPtr: + case Instruction::Store: + case Instruction::Br: + case Instruction::Switch: return true; - return EqualTypeSize(I->getOperand(0)); - } - - if (GenerateSignBits(V)) { - LLVM_DEBUG(dbgs() << "ARM CGP: No, instruction can generate sign bits.\n"); - return false; - } - - // Memory instructions - if (isa(V) || isa(V)) - return true; - - // Branches and targets. - if( isa(V) || isa(V) || isa(V)) - return true; - - // Non-instruction values that we can handle. - if ((isa(V) && !isa(V)) || isa(V)) - return isSupportedType(V); - - if (isa(V) || isa(V) || isa(V) || - isa(V)) + case Instruction::PHI: + case Instruction::Select: + case Instruction::Ret: + case Instruction::Load: + case Instruction::Trunc: + case Instruction::BitCast: + return isSupportedType(I); + case Instruction::ZExt: + return isSupportedType(I->getOperand(0)); + case Instruction::ICmp: + // Now that we allow small types than TypeSize, only allow icmp of + // TypeSize because they will require a trunc to be legalised. + // TODO: Allow icmp of smaller types, and calculate at the end + // whether the transform would be beneficial. + if (isa(I->getOperand(0)->getType())) + return true; + return EqualTypeSize(I->getOperand(0)); + case Instruction::Call: { + // Special cases for calls as we need to check for zeroext + // TODO We should accept calls even if they don't have zeroext, as they + // can still be sinks. + auto *Call = cast(I); + return isSupportedType(Call) && + Call->hasRetAttr(Attribute::AttrKind::ZExt); + } + } + } else if (isa(V) && !isa(V)) { return isSupportedType(V); + } else if (auto *Arg = dyn_cast(V)) + return isSupportedType(V) && !Arg->hasSExtAttr(); - if (auto *Cast = dyn_cast(V)) - return isSupportedType(Cast) || isSupportedType(Cast->getOperand(0)); - - // Special cases for calls as we need to check for zeroext - // TODO We should accept calls even if they don't have zeroext, as they can - // still be sinks. - if (auto *Call = dyn_cast(V)) - return isSupportedType(Call) && - Call->hasRetAttr(Attribute::AttrKind::ZExt); - - if (!isa(V)) - return false; - - if (!isSupportedType(V)) - return false; - - return true; + return isa(V); } /// Check that the type of V would be promoted and that the original type is