@@ -187,8 +187,7 @@ static bool GenerateSignBits(Value *V) {
187
187
188
188
unsigned Opc = cast<Instruction>(V)->getOpcode ();
189
189
return Opc == Instruction::AShr || Opc == Instruction::SDiv ||
190
- Opc == Instruction::SRem || Opc == Instruction::SExt ||
191
- Opc == Instruction::SIToFP;
190
+ Opc == Instruction::SRem || Opc == Instruction::SExt;
192
191
}
193
192
194
193
static bool EqualTypeSize (Value *V) {
@@ -806,54 +805,48 @@ void IRPromoter::Mutate(Type *OrigTy,
806
805
// / return value is zeroext. We don't allow opcodes that can introduce sign
807
806
// / bits.
808
807
bool ARMCodeGenPrepare::isSupportedValue (Value *V) {
809
- if (auto *I = dyn_cast<ICmpInst>(V)) {
810
- // Now that we allow small types than TypeSize, only allow icmp of
811
- // TypeSize because they will require a trunc to be legalised.
812
- // TODO: Allow icmp of smaller types, and calculate at the end
813
- // whether the transform would be beneficial.
814
- if (isa<PointerType>(I->getOperand (0 )->getType ()))
808
+ if (auto *I = dyn_cast<Instruction>(V)) {
809
+ switch (I->getOpcode ()) {
810
+ default :
811
+ return isa<BinaryOperator>(I) && isSupportedType (I) &&
812
+ !GenerateSignBits (I);
813
+ case Instruction::GetElementPtr:
814
+ case Instruction::Store:
815
+ case Instruction::Br:
816
+ case Instruction::Switch:
815
817
return true ;
816
- return EqualTypeSize (I->getOperand (0 ));
817
- }
818
-
819
- if (GenerateSignBits (V)) {
820
- LLVM_DEBUG (dbgs () << " ARM CGP: No, instruction can generate sign bits.\n " );
821
- return false ;
822
- }
823
-
824
- // Memory instructions
825
- if (isa<StoreInst>(V) || isa<GetElementPtrInst>(V))
826
- return true ;
827
-
828
- // Branches and targets.
829
- if ( isa<BranchInst>(V) || isa<SwitchInst>(V) || isa<BasicBlock>(V))
830
- return true ;
831
-
832
- // Non-instruction values that we can handle.
833
- if ((isa<Constant>(V) && !isa<ConstantExpr>(V)) || isa<Argument>(V))
834
- return isSupportedType (V);
835
-
836
- if (isa<PHINode>(V) || isa<SelectInst>(V) || isa<ReturnInst>(V) ||
837
- isa<LoadInst>(V))
818
+ case Instruction::PHI:
819
+ case Instruction::Select:
820
+ case Instruction::Ret:
821
+ case Instruction::Load:
822
+ case Instruction::Trunc:
823
+ case Instruction::BitCast:
824
+ return isSupportedType (I);
825
+ case Instruction::ZExt:
826
+ return isSupportedType (I->getOperand (0 ));
827
+ case Instruction::ICmp:
828
+ // Now that we allow small types than TypeSize, only allow icmp of
829
+ // TypeSize because they will require a trunc to be legalised.
830
+ // TODO: Allow icmp of smaller types, and calculate at the end
831
+ // whether the transform would be beneficial.
832
+ if (isa<PointerType>(I->getOperand (0 )->getType ()))
833
+ return true ;
834
+ return EqualTypeSize (I->getOperand (0 ));
835
+ case Instruction::Call: {
836
+ // Special cases for calls as we need to check for zeroext
837
+ // TODO We should accept calls even if they don't have zeroext, as they
838
+ // can still be sinks.
839
+ auto *Call = cast<CallInst>(I);
840
+ return isSupportedType (Call) &&
841
+ Call->hasRetAttr (Attribute::AttrKind::ZExt);
842
+ }
843
+ }
844
+ } else if (isa<Constant>(V) && !isa<ConstantExpr>(V)) {
838
845
return isSupportedType (V);
846
+ } else if (auto *Arg = dyn_cast<Argument>(V))
847
+ return isSupportedType (V) && !Arg->hasSExtAttr ();
839
848
840
- if (auto *Cast = dyn_cast<CastInst>(V))
841
- return isSupportedType (Cast) || isSupportedType (Cast->getOperand (0 ));
842
-
843
- // Special cases for calls as we need to check for zeroext
844
- // TODO We should accept calls even if they don't have zeroext, as they can
845
- // still be sinks.
846
- if (auto *Call = dyn_cast<CallInst>(V))
847
- return isSupportedType (Call) &&
848
- Call->hasRetAttr (Attribute::AttrKind::ZExt);
849
-
850
- if (!isa<BinaryOperator>(V))
851
- return false ;
852
-
853
- if (!isSupportedType (V))
854
- return false ;
855
-
856
- return true ;
849
+ return isa<BasicBlock>(V);
857
850
}
858
851
859
852
// / Check that the type of V would be promoted and that the original type is
0 commit comments