diff options
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 9e21a7e..cf472ae 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -902,12 +902,11 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, /// folding using this function strips this information. /// static Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, + Type *DestTy, unsigned Opcode, ArrayRef<Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI) { - Type *DestTy = InstOrCE->getType(); - // Handle easy binops first. if (Instruction::isBinaryOp(Opcode)) return ConstantFoldBinaryOpOperands(Opcode, Ops[0], Ops[1], DL); @@ -1040,7 +1039,8 @@ ConstantFoldConstantExpressionImpl(const ConstantExpr *CE, const DataLayout &DL, return ConstantFoldCompareInstOperands(CE->getPredicate(), Ops[0], Ops[1], DL, TLI); - return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI); + return ConstantFoldInstOperandsImpl(CE, CE->getType(), CE->getOpcode(), Ops, + DL, TLI); } Constant *llvm::ConstantFoldConstantExpression(const ConstantExpr *CE, @@ -1054,7 +1054,16 @@ Constant *llvm::ConstantFoldInstOperands(Instruction *I, ArrayRef<Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI) { - return ConstantFoldInstOperandsImpl(I, I->getOpcode(), Ops, DL, TLI); + return ConstantFoldInstOperandsImpl(I, I->getType(), I->getOpcode(), Ops, DL, + TLI); +} + +Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, + ArrayRef<Constant *> Ops, + const DataLayout &DL, + const TargetLibraryInfo *TLI) { + assert(Opcode != Instruction::GetElementPtr && "Invalid for GEPs"); + return ConstantFoldInstOperandsImpl(nullptr, DestTy, Opcode, Ops, DL, TLI); } Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, |