From 29e3b2ba77e487cd595185ad11dbba71c45fb42f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 5 Nov 2003 19:53:03 +0000 Subject: [PATCH] Add support for constant expr shifts git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9735 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/ConstantReader.cpp | 2 ++ lib/VMCore/Constants.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 097bdbe1266..00f44b3665e 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -182,6 +182,8 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf, } else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr std::vector IdxList(ArgVec.begin()+1, ArgVec.end()); return ConstantExpr::getGetElementPtr(ArgVec[0], IdxList); + } else if (Opcode == Instruction::Shl || Opcode == Instruction::Shr) { + return ConstantExpr::getShift(Opcode, ArgVec[0], ArgVec[1]); } else { // All other 2-operand expressions return ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]); } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index bc1e9d2c1c8..28cc9d24e03 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -493,6 +493,13 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV, } else if (getOpcode() == Instruction::Cast) { assert(getOperand(0) == From && "Cast only has one use!"); Replacement = ConstantExpr::getCast(To, getType()); + } else if (getOpcode() == Instruction::Shl || + getOpcode() == Instruction::Shr) { + Constant *C1 = getOperand(0); + Constant *C2 = getOperand(1); + if (C1 == From) C1 = To; + if (C2 == From) C2 = To; + Replacement = ConstantExpr::getShift(getOpcode(), C1, C2); } else if (getNumOperands() == 2) { Constant *C1 = getOperand(0); Constant *C2 = getOperand(1); -- 2.34.1