mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 18:34:09 +00:00
Changes to support making the shift instructions be true BinaryOperators.
This feature is needed in order to support shifts of more than 255 bits on large integer types. This changes the syntax for llvm assembly to make shl, ashr and lshr instructions look like a binary operator: shl i32 %X, 1 instead of shl i32 %X, i8 1 Additionally, this should help a few passes perform additional optimizations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9a2ef9509e
commit
832254e1c2
@ -442,8 +442,6 @@ protected:
|
||||
Constant *C1, Constant *C2);
|
||||
static Constant *getCompareTy(unsigned short pred, Constant *C1,
|
||||
Constant *C2);
|
||||
static Constant *getShiftTy(const Type *Ty,
|
||||
unsigned Opcode, Constant *C1, Constant *C2);
|
||||
static Constant *getSelectTy(const Type *Ty,
|
||||
Constant *C1, Constant *C2, Constant *C3);
|
||||
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
|
||||
|
@ -114,49 +114,49 @@ HANDLE_BINARY_INST(13, URem , BinaryOperator)
|
||||
HANDLE_BINARY_INST(14, SRem , BinaryOperator)
|
||||
HANDLE_BINARY_INST(15, FRem , BinaryOperator)
|
||||
|
||||
// Logical operators...
|
||||
HANDLE_BINARY_INST(16, And , BinaryOperator)
|
||||
HANDLE_BINARY_INST(17, Or , BinaryOperator)
|
||||
HANDLE_BINARY_INST(18, Xor , BinaryOperator)
|
||||
LAST_BINARY_INST(18)
|
||||
// Logical operators (integer operands)
|
||||
HANDLE_BINARY_INST(16, Shl , BinaryOperator) // Shift left (logical)
|
||||
HANDLE_BINARY_INST(17, LShr , BinaryOperator) // Shift right (logical)
|
||||
HANDLE_BINARY_INST(18, AShr , BinaryOperator) // shift right (arithmetic)
|
||||
HANDLE_BINARY_INST(19, And , BinaryOperator)
|
||||
HANDLE_BINARY_INST(20, Or , BinaryOperator)
|
||||
HANDLE_BINARY_INST(21, Xor , BinaryOperator)
|
||||
LAST_BINARY_INST(21)
|
||||
|
||||
// Memory operators...
|
||||
FIRST_MEMORY_INST(19)
|
||||
HANDLE_MEMORY_INST(19, Malloc, MallocInst) // Heap management instructions
|
||||
HANDLE_MEMORY_INST(20, Free , FreeInst )
|
||||
HANDLE_MEMORY_INST(21, Alloca, AllocaInst) // Stack management
|
||||
HANDLE_MEMORY_INST(22, Load , LoadInst ) // Memory manipulation instrs
|
||||
HANDLE_MEMORY_INST(23, Store , StoreInst )
|
||||
HANDLE_MEMORY_INST(24, GetElementPtr, GetElementPtrInst)
|
||||
LAST_MEMORY_INST(24)
|
||||
FIRST_MEMORY_INST(22)
|
||||
HANDLE_MEMORY_INST(22, Malloc, MallocInst) // Heap management instructions
|
||||
HANDLE_MEMORY_INST(23, Free , FreeInst )
|
||||
HANDLE_MEMORY_INST(24, Alloca, AllocaInst) // Stack management
|
||||
HANDLE_MEMORY_INST(25, Load , LoadInst ) // Memory manipulation instrs
|
||||
HANDLE_MEMORY_INST(26, Store , StoreInst )
|
||||
HANDLE_MEMORY_INST(27, GetElementPtr, GetElementPtrInst)
|
||||
LAST_MEMORY_INST(27)
|
||||
|
||||
// Cast operators ...
|
||||
// NOTE: The order matters here because CastInst::isEliminableCastPair
|
||||
// NOTE: (see Instructions.cpp) encodes a table based on this ordering.
|
||||
FIRST_CAST_INST(25)
|
||||
HANDLE_CAST_INST(25, Trunc , TruncInst ) // Truncate integers
|
||||
HANDLE_CAST_INST(26, ZExt , ZExtInst ) // Zero extend integers
|
||||
HANDLE_CAST_INST(27, SExt , SExtInst ) // Sign extend integers
|
||||
HANDLE_CAST_INST(28, FPToUI , FPToUIInst ) // floating point -> UInt
|
||||
HANDLE_CAST_INST(29, FPToSI , FPToSIInst ) // floating point -> SInt
|
||||
HANDLE_CAST_INST(30, UIToFP , UIToFPInst ) // UInt -> floating point
|
||||
HANDLE_CAST_INST(31, SIToFP , SIToFPInst ) // SInt -> floating point
|
||||
HANDLE_CAST_INST(32, FPTrunc , FPTruncInst ) // Truncate floating point
|
||||
HANDLE_CAST_INST(33, FPExt , FPExtInst ) // Extend floating point
|
||||
HANDLE_CAST_INST(34, PtrToInt, PtrToIntInst) // Pointer -> Integer
|
||||
HANDLE_CAST_INST(35, IntToPtr, IntToPtrInst) // Integer -> Pointer
|
||||
HANDLE_CAST_INST(36, BitCast , BitCastInst ) // Type cast
|
||||
LAST_CAST_INST(36)
|
||||
FIRST_CAST_INST(28)
|
||||
HANDLE_CAST_INST(28, Trunc , TruncInst ) // Truncate integers
|
||||
HANDLE_CAST_INST(29, ZExt , ZExtInst ) // Zero extend integers
|
||||
HANDLE_CAST_INST(30, SExt , SExtInst ) // Sign extend integers
|
||||
HANDLE_CAST_INST(31, FPToUI , FPToUIInst ) // floating point -> UInt
|
||||
HANDLE_CAST_INST(32, FPToSI , FPToSIInst ) // floating point -> SInt
|
||||
HANDLE_CAST_INST(33, UIToFP , UIToFPInst ) // UInt -> floating point
|
||||
HANDLE_CAST_INST(34, SIToFP , SIToFPInst ) // SInt -> floating point
|
||||
HANDLE_CAST_INST(35, FPTrunc , FPTruncInst ) // Truncate floating point
|
||||
HANDLE_CAST_INST(36, FPExt , FPExtInst ) // Extend floating point
|
||||
HANDLE_CAST_INST(37, PtrToInt, PtrToIntInst) // Pointer -> Integer
|
||||
HANDLE_CAST_INST(38, IntToPtr, IntToPtrInst) // Integer -> Pointer
|
||||
HANDLE_CAST_INST(39, BitCast , BitCastInst ) // Type cast
|
||||
LAST_CAST_INST(39)
|
||||
|
||||
// Other operators...
|
||||
FIRST_OTHER_INST(37)
|
||||
HANDLE_OTHER_INST(37, ICmp , ICmpInst ) // Integer comparison instruction
|
||||
HANDLE_OTHER_INST(38, FCmp , FCmpInst ) // Floating point comparison instr.
|
||||
HANDLE_OTHER_INST(39, PHI , PHINode ) // PHI node instruction
|
||||
HANDLE_OTHER_INST(40, Call , CallInst ) // Call a function
|
||||
HANDLE_OTHER_INST(41, Shl , ShiftInst ) // Shift Left operations (logical)
|
||||
HANDLE_OTHER_INST(42, LShr , ShiftInst ) // Logical Shift right (unsigned)
|
||||
HANDLE_OTHER_INST(43, AShr , ShiftInst ) // Arithmetic shift right (signed)
|
||||
FIRST_OTHER_INST(40)
|
||||
HANDLE_OTHER_INST(40, ICmp , ICmpInst ) // Integer comparison instruction
|
||||
HANDLE_OTHER_INST(41, FCmp , FCmpInst ) // Floating point comparison instr.
|
||||
HANDLE_OTHER_INST(42, PHI , PHINode ) // PHI node instruction
|
||||
HANDLE_OTHER_INST(43, Call , CallInst ) // Call a function
|
||||
HANDLE_OTHER_INST(44, Select , SelectInst ) // select instruction
|
||||
HANDLE_OTHER_INST(45, UserOp1, Instruction) // May be used internally in a pass
|
||||
HANDLE_OTHER_INST(46, UserOp2, Instruction) // Internal to passes only
|
||||
|
@ -129,6 +129,27 @@ public:
|
||||
return getOpcode() >= BinaryOpsBegin && getOpcode() < BinaryOpsEnd;
|
||||
}
|
||||
|
||||
/// @brief Determine if the Opcode is one of the shift instructions.
|
||||
static inline bool isShift(unsigned Opcode) {
|
||||
return Opcode >= Shl && Opcode <= AShr;
|
||||
}
|
||||
|
||||
/// @brief Determine if the instruction's opcode is one of the shift
|
||||
/// instructions.
|
||||
inline bool isShift() { return isShift(getOpcode()); }
|
||||
|
||||
/// isLogicalShift - Return true if this is a logical shift left or a logical
|
||||
/// shift right.
|
||||
inline bool isLogicalShift() {
|
||||
return getOpcode() == Shl || getOpcode() == LShr;
|
||||
}
|
||||
|
||||
/// isLogicalShift - Return true if this is a logical shift left or a logical
|
||||
/// shift right.
|
||||
inline bool isArithmeticShift() {
|
||||
return getOpcode() == AShr;
|
||||
}
|
||||
|
||||
/// @brief Determine if the OpCode is one of the CastInst instructions.
|
||||
static inline bool isCast(unsigned OpCode) {
|
||||
return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
|
||||
|
@ -760,83 +760,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ShiftInst Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// ShiftInst - This class represents left and right shift instructions.
|
||||
///
|
||||
class ShiftInst : public Instruction {
|
||||
Use Ops[2];
|
||||
ShiftInst(const ShiftInst &SI)
|
||||
: Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
|
||||
Ops[0].init(SI.Ops[0], this);
|
||||
Ops[1].init(SI.Ops[1], this);
|
||||
}
|
||||
void init(OtherOps Opcode, Value *S, Value *SA) {
|
||||
assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) &&
|
||||
"ShiftInst Opcode invalid!");
|
||||
Ops[0].init(S, this);
|
||||
Ops[1].init(SA, this);
|
||||
}
|
||||
|
||||
public:
|
||||
ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
|
||||
Instruction *InsertBefore = 0)
|
||||
: Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
|
||||
init(Opcode, S, SA);
|
||||
}
|
||||
ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
|
||||
BasicBlock *InsertAtEnd)
|
||||
: Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
|
||||
init(Opcode, S, SA);
|
||||
}
|
||||
|
||||
OtherOps getOpcode() const {
|
||||
return static_cast<OtherOps>(Instruction::getOpcode());
|
||||
}
|
||||
|
||||
/// Transparently provide more efficient getOperand methods.
|
||||
Value *getOperand(unsigned i) const {
|
||||
assert(i < 2 && "getOperand() out of range!");
|
||||
return Ops[i];
|
||||
}
|
||||
void setOperand(unsigned i, Value *Val) {
|
||||
assert(i < 2 && "setOperand() out of range!");
|
||||
Ops[i] = Val;
|
||||
}
|
||||
unsigned getNumOperands() const { return 2; }
|
||||
|
||||
/// isLogicalShift - Return true if this is a logical shift left or a logical
|
||||
/// shift right.
|
||||
bool isLogicalShift() const {
|
||||
unsigned opcode = getOpcode();
|
||||
return opcode == Instruction::Shl || opcode == Instruction::LShr;
|
||||
}
|
||||
|
||||
|
||||
/// isArithmeticShift - Return true if this is a sign-extending shift right
|
||||
/// operation.
|
||||
bool isArithmeticShift() const {
|
||||
return !isLogicalShift();
|
||||
}
|
||||
|
||||
|
||||
virtual ShiftInst *clone() const;
|
||||
|
||||
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const ShiftInst *) { return true; }
|
||||
static inline bool classof(const Instruction *I) {
|
||||
return (I->getOpcode() == Instruction::LShr) |
|
||||
(I->getOpcode() == Instruction::AShr) |
|
||||
(I->getOpcode() == Instruction::Shl);
|
||||
}
|
||||
static inline bool classof(const Value *V) {
|
||||
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
||||
}
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SelectInst Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -190,7 +190,6 @@ public:
|
||||
RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst); }
|
||||
RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction); }
|
||||
RetTy visitCallInst(CallInst &I) { DELEGATE(Instruction); }
|
||||
RetTy visitShiftInst(ShiftInst &I) { DELEGATE(Instruction); }
|
||||
RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(Instruction); }
|
||||
RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
|
||||
RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction); }
|
||||
|
@ -166,27 +166,27 @@ inline BinaryOp_match<LHS, RHS, Instruction::Xor> m_Xor(const LHS &L,
|
||||
}
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::Shl,
|
||||
ShiftInst> m_Shl(const LHS &L, const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::Shl, ShiftInst>(L, R);
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::Shl> m_Shl(const LHS &L,
|
||||
const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::Shl>(L, R);
|
||||
}
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::LShr,
|
||||
ShiftInst> m_LShr(const LHS &L, const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::LShr, ShiftInst>(L, R);
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::LShr> m_LShr(const LHS &L,
|
||||
const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::LShr>(L, R);
|
||||
}
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::AShr,
|
||||
ShiftInst> m_AShr(const LHS &L, const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::AShr, ShiftInst>(L, R);
|
||||
inline BinaryOp_match<LHS, RHS, Instruction::AShr> m_AShr(const LHS &L,
|
||||
const RHS &R) {
|
||||
return BinaryOp_match<LHS, RHS, Instruction::AShr>(L, R);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Matchers for either AShr or LShr .. for convenience
|
||||
//
|
||||
template<typename LHS_t, typename RHS_t, typename ConcreteTy = ShiftInst>
|
||||
template<typename LHS_t, typename RHS_t, typename ConcreteTy = BinaryOperator>
|
||||
struct Shr_match {
|
||||
LHS_t L;
|
||||
RHS_t R;
|
||||
@ -248,18 +248,18 @@ struct BinaryOpClass_match {
|
||||
};
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
inline BinaryOpClass_match<LHS, RHS, ShiftInst, Instruction::OtherOps>
|
||||
m_Shift(Instruction::OtherOps &Op, const LHS &L, const RHS &R) {
|
||||
inline BinaryOpClass_match<LHS, RHS, BinaryOperator, Instruction::BinaryOps>
|
||||
m_Shift(Instruction::BinaryOps &Op, const LHS &L, const RHS &R) {
|
||||
return BinaryOpClass_match<LHS, RHS,
|
||||
ShiftInst, Instruction::OtherOps>(Op, L, R);
|
||||
BinaryOperator, Instruction::BinaryOps>(Op, L, R);
|
||||
}
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
inline BinaryOpClass_match<LHS, RHS, ShiftInst, Instruction::OtherOps>
|
||||
inline BinaryOpClass_match<LHS, RHS, BinaryOperator, Instruction::BinaryOps>
|
||||
m_Shift(const LHS &L, const RHS &R) {
|
||||
Instruction::OtherOps Op;
|
||||
Instruction::BinaryOps Op;
|
||||
return BinaryOpClass_match<LHS, RHS,
|
||||
ShiftInst, Instruction::OtherOps>(Op, L, R);
|
||||
BinaryOperator, Instruction::BinaryOps>(Op, L, R);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -216,10 +216,6 @@ Constant *llvm::ConstantFoldInstOperands(const Instruction* I,
|
||||
case Instruction::FCmp:
|
||||
return ConstantExpr::getCompare(cast<CmpInst>(I)->getPredicate(), Ops[0],
|
||||
Ops[1]);
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
return ConstantExpr::get(Opc, Ops[0], Ops[1]);
|
||||
case Instruction::Trunc:
|
||||
case Instruction::ZExt:
|
||||
case Instruction::SExt:
|
||||
|
@ -776,9 +776,6 @@ void Andersens::visitInstruction(Instruction &I) {
|
||||
case Instruction::Unwind:
|
||||
case Instruction::Unreachable:
|
||||
case Instruction::Free:
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
case Instruction::ICmp:
|
||||
case Instruction::FCmp:
|
||||
return;
|
||||
|
@ -1736,7 +1736,7 @@ ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS,
|
||||
/// CanConstantFold - Return true if we can constant fold an instruction of the
|
||||
/// specified type, assuming that all operands were constants.
|
||||
static bool CanConstantFold(const Instruction *I) {
|
||||
if (isa<BinaryOperator>(I) || isa<ShiftInst>(I) || isa<CmpInst>(I) ||
|
||||
if (isa<BinaryOperator>(I) || isa<CmpInst>(I) ||
|
||||
isa<SelectInst>(I) || isa<CastInst>(I) || isa<GetElementPtrInst>(I))
|
||||
return true;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -232,6 +232,9 @@ coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
|
||||
void { RET_TY(Type::VoidTy, VOID); }
|
||||
float { RET_TY(Type::FloatTy, FLOAT); }
|
||||
double { RET_TY(Type::DoubleTy,DOUBLE);}
|
||||
@ -255,11 +258,15 @@ fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
|
||||
urem { RET_TOK(BinaryOpVal, URem, UREM); }
|
||||
srem { RET_TOK(BinaryOpVal, SRem, SREM); }
|
||||
frem { RET_TOK(BinaryOpVal, FRem, FREM); }
|
||||
shl { RET_TOK(BinaryOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
|
||||
and { RET_TOK(BinaryOpVal, And, AND); }
|
||||
or { RET_TOK(BinaryOpVal, Or , OR ); }
|
||||
xor { RET_TOK(BinaryOpVal, Xor, XOR); }
|
||||
icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
|
||||
|
||||
eq { return EQ; }
|
||||
ne { return NE; }
|
||||
slt { return SLT; }
|
||||
@ -286,8 +293,6 @@ call { RET_TOK(OtherOpVal, Call, CALL); }
|
||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||
@ -298,9 +303,6 @@ inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
|
||||
ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, Select, SELECT); }
|
||||
shl { RET_TOK(OtherOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(OtherOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(OtherOpVal, AShr, ASHR); }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
ret { RET_TOK(TermOpVal, Ret, RET); }
|
||||
br { RET_TOK(TermOpVal, Br, BR); }
|
||||
|
@ -232,6 +232,9 @@ coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
|
||||
void { RET_TY(Type::VoidTy, VOID); }
|
||||
float { RET_TY(Type::FloatTy, FLOAT); }
|
||||
double { RET_TY(Type::DoubleTy,DOUBLE);}
|
||||
@ -255,11 +258,15 @@ fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
|
||||
urem { RET_TOK(BinaryOpVal, URem, UREM); }
|
||||
srem { RET_TOK(BinaryOpVal, SRem, SREM); }
|
||||
frem { RET_TOK(BinaryOpVal, FRem, FREM); }
|
||||
shl { RET_TOK(BinaryOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
|
||||
and { RET_TOK(BinaryOpVal, And, AND); }
|
||||
or { RET_TOK(BinaryOpVal, Or , OR ); }
|
||||
xor { RET_TOK(BinaryOpVal, Xor, XOR); }
|
||||
icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
|
||||
|
||||
eq { return EQ; }
|
||||
ne { return NE; }
|
||||
slt { return SLT; }
|
||||
@ -286,8 +293,6 @@ call { RET_TOK(OtherOpVal, Call, CALL); }
|
||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||
@ -298,9 +303,6 @@ inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
|
||||
ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, Select, SELECT); }
|
||||
shl { RET_TOK(OtherOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(OtherOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(OtherOpVal, AShr, ASHR); }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
ret { RET_TOK(TermOpVal, Ret, RET); }
|
||||
br { RET_TOK(TermOpVal, Br, BR); }
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,302 @@
|
||||
typedef union {
|
||||
/* A Bison parser, made by GNU Bison 2.1. */
|
||||
|
||||
/* Skeleton parser for Yacc-like parsing with Bison,
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* As a special exception, when this file is copied by Bison into a
|
||||
Bison output file, you may use that output file without restriction.
|
||||
This special exception was added by the Free Software Foundation
|
||||
in version 1.24 of Bison. */
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
ESINT64VAL = 258,
|
||||
EUINT64VAL = 259,
|
||||
LOCALVAL_ID = 260,
|
||||
GLOBALVAL_ID = 261,
|
||||
FPVAL = 262,
|
||||
VOID = 263,
|
||||
INTTYPE = 264,
|
||||
FLOAT = 265,
|
||||
DOUBLE = 266,
|
||||
LABEL = 267,
|
||||
TYPE = 268,
|
||||
LOCALVAR = 269,
|
||||
GLOBALVAR = 270,
|
||||
LABELSTR = 271,
|
||||
STRINGCONSTANT = 272,
|
||||
ATSTRINGCONSTANT = 273,
|
||||
IMPLEMENTATION = 274,
|
||||
ZEROINITIALIZER = 275,
|
||||
TRUETOK = 276,
|
||||
FALSETOK = 277,
|
||||
BEGINTOK = 278,
|
||||
ENDTOK = 279,
|
||||
DECLARE = 280,
|
||||
DEFINE = 281,
|
||||
GLOBAL = 282,
|
||||
CONSTANT = 283,
|
||||
SECTION = 284,
|
||||
VOLATILE = 285,
|
||||
TO = 286,
|
||||
DOTDOTDOT = 287,
|
||||
NULL_TOK = 288,
|
||||
UNDEF = 289,
|
||||
INTERNAL = 290,
|
||||
LINKONCE = 291,
|
||||
WEAK = 292,
|
||||
APPENDING = 293,
|
||||
DLLIMPORT = 294,
|
||||
DLLEXPORT = 295,
|
||||
EXTERN_WEAK = 296,
|
||||
OPAQUE = 297,
|
||||
EXTERNAL = 298,
|
||||
TARGET = 299,
|
||||
TRIPLE = 300,
|
||||
ALIGN = 301,
|
||||
DEPLIBS = 302,
|
||||
CALL = 303,
|
||||
TAIL = 304,
|
||||
ASM_TOK = 305,
|
||||
MODULE = 306,
|
||||
SIDEEFFECT = 307,
|
||||
CC_TOK = 308,
|
||||
CCC_TOK = 309,
|
||||
FASTCC_TOK = 310,
|
||||
COLDCC_TOK = 311,
|
||||
X86_STDCALLCC_TOK = 312,
|
||||
X86_FASTCALLCC_TOK = 313,
|
||||
DATALAYOUT = 314,
|
||||
RET = 315,
|
||||
BR = 316,
|
||||
SWITCH = 317,
|
||||
INVOKE = 318,
|
||||
UNWIND = 319,
|
||||
UNREACHABLE = 320,
|
||||
ADD = 321,
|
||||
SUB = 322,
|
||||
MUL = 323,
|
||||
UDIV = 324,
|
||||
SDIV = 325,
|
||||
FDIV = 326,
|
||||
UREM = 327,
|
||||
SREM = 328,
|
||||
FREM = 329,
|
||||
AND = 330,
|
||||
OR = 331,
|
||||
XOR = 332,
|
||||
SHL = 333,
|
||||
LSHR = 334,
|
||||
ASHR = 335,
|
||||
ICMP = 336,
|
||||
FCMP = 337,
|
||||
EQ = 338,
|
||||
NE = 339,
|
||||
SLT = 340,
|
||||
SGT = 341,
|
||||
SLE = 342,
|
||||
SGE = 343,
|
||||
ULT = 344,
|
||||
UGT = 345,
|
||||
ULE = 346,
|
||||
UGE = 347,
|
||||
OEQ = 348,
|
||||
ONE = 349,
|
||||
OLT = 350,
|
||||
OGT = 351,
|
||||
OLE = 352,
|
||||
OGE = 353,
|
||||
ORD = 354,
|
||||
UNO = 355,
|
||||
UEQ = 356,
|
||||
UNE = 357,
|
||||
MALLOC = 358,
|
||||
ALLOCA = 359,
|
||||
FREE = 360,
|
||||
LOAD = 361,
|
||||
STORE = 362,
|
||||
GETELEMENTPTR = 363,
|
||||
TRUNC = 364,
|
||||
ZEXT = 365,
|
||||
SEXT = 366,
|
||||
FPTRUNC = 367,
|
||||
FPEXT = 368,
|
||||
BITCAST = 369,
|
||||
UITOFP = 370,
|
||||
SITOFP = 371,
|
||||
FPTOUI = 372,
|
||||
FPTOSI = 373,
|
||||
INTTOPTR = 374,
|
||||
PTRTOINT = 375,
|
||||
PHI_TOK = 376,
|
||||
SELECT = 377,
|
||||
VAARG = 378,
|
||||
EXTRACTELEMENT = 379,
|
||||
INSERTELEMENT = 380,
|
||||
SHUFFLEVECTOR = 381,
|
||||
NORETURN = 382,
|
||||
INREG = 383,
|
||||
SRET = 384,
|
||||
DEFAULT = 385,
|
||||
HIDDEN = 386
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
#define ESINT64VAL 258
|
||||
#define EUINT64VAL 259
|
||||
#define LOCALVAL_ID 260
|
||||
#define GLOBALVAL_ID 261
|
||||
#define FPVAL 262
|
||||
#define VOID 263
|
||||
#define INTTYPE 264
|
||||
#define FLOAT 265
|
||||
#define DOUBLE 266
|
||||
#define LABEL 267
|
||||
#define TYPE 268
|
||||
#define LOCALVAR 269
|
||||
#define GLOBALVAR 270
|
||||
#define LABELSTR 271
|
||||
#define STRINGCONSTANT 272
|
||||
#define ATSTRINGCONSTANT 273
|
||||
#define IMPLEMENTATION 274
|
||||
#define ZEROINITIALIZER 275
|
||||
#define TRUETOK 276
|
||||
#define FALSETOK 277
|
||||
#define BEGINTOK 278
|
||||
#define ENDTOK 279
|
||||
#define DECLARE 280
|
||||
#define DEFINE 281
|
||||
#define GLOBAL 282
|
||||
#define CONSTANT 283
|
||||
#define SECTION 284
|
||||
#define VOLATILE 285
|
||||
#define TO 286
|
||||
#define DOTDOTDOT 287
|
||||
#define NULL_TOK 288
|
||||
#define UNDEF 289
|
||||
#define INTERNAL 290
|
||||
#define LINKONCE 291
|
||||
#define WEAK 292
|
||||
#define APPENDING 293
|
||||
#define DLLIMPORT 294
|
||||
#define DLLEXPORT 295
|
||||
#define EXTERN_WEAK 296
|
||||
#define OPAQUE 297
|
||||
#define EXTERNAL 298
|
||||
#define TARGET 299
|
||||
#define TRIPLE 300
|
||||
#define ALIGN 301
|
||||
#define DEPLIBS 302
|
||||
#define CALL 303
|
||||
#define TAIL 304
|
||||
#define ASM_TOK 305
|
||||
#define MODULE 306
|
||||
#define SIDEEFFECT 307
|
||||
#define CC_TOK 308
|
||||
#define CCC_TOK 309
|
||||
#define FASTCC_TOK 310
|
||||
#define COLDCC_TOK 311
|
||||
#define X86_STDCALLCC_TOK 312
|
||||
#define X86_FASTCALLCC_TOK 313
|
||||
#define DATALAYOUT 314
|
||||
#define RET 315
|
||||
#define BR 316
|
||||
#define SWITCH 317
|
||||
#define INVOKE 318
|
||||
#define UNWIND 319
|
||||
#define UNREACHABLE 320
|
||||
#define ADD 321
|
||||
#define SUB 322
|
||||
#define MUL 323
|
||||
#define UDIV 324
|
||||
#define SDIV 325
|
||||
#define FDIV 326
|
||||
#define UREM 327
|
||||
#define SREM 328
|
||||
#define FREM 329
|
||||
#define AND 330
|
||||
#define OR 331
|
||||
#define XOR 332
|
||||
#define SHL 333
|
||||
#define LSHR 334
|
||||
#define ASHR 335
|
||||
#define ICMP 336
|
||||
#define FCMP 337
|
||||
#define EQ 338
|
||||
#define NE 339
|
||||
#define SLT 340
|
||||
#define SGT 341
|
||||
#define SLE 342
|
||||
#define SGE 343
|
||||
#define ULT 344
|
||||
#define UGT 345
|
||||
#define ULE 346
|
||||
#define UGE 347
|
||||
#define OEQ 348
|
||||
#define ONE 349
|
||||
#define OLT 350
|
||||
#define OGT 351
|
||||
#define OLE 352
|
||||
#define OGE 353
|
||||
#define ORD 354
|
||||
#define UNO 355
|
||||
#define UEQ 356
|
||||
#define UNE 357
|
||||
#define MALLOC 358
|
||||
#define ALLOCA 359
|
||||
#define FREE 360
|
||||
#define LOAD 361
|
||||
#define STORE 362
|
||||
#define GETELEMENTPTR 363
|
||||
#define TRUNC 364
|
||||
#define ZEXT 365
|
||||
#define SEXT 366
|
||||
#define FPTRUNC 367
|
||||
#define FPEXT 368
|
||||
#define BITCAST 369
|
||||
#define UITOFP 370
|
||||
#define SITOFP 371
|
||||
#define FPTOUI 372
|
||||
#define FPTOSI 373
|
||||
#define INTTOPTR 374
|
||||
#define PTRTOINT 375
|
||||
#define PHI_TOK 376
|
||||
#define SELECT 377
|
||||
#define VAARG 378
|
||||
#define EXTRACTELEMENT 379
|
||||
#define INSERTELEMENT 380
|
||||
#define SHUFFLEVECTOR 381
|
||||
#define NORETURN 382
|
||||
#define INREG 383
|
||||
#define SRET 384
|
||||
#define DEFAULT 385
|
||||
#define HIDDEN 386
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
|
||||
#line 886 "/proj/llvm/llvm-4/lib/AsmParser/llvmAsmParser.y"
|
||||
typedef union YYSTYPE {
|
||||
llvm::Module *ModuleVal;
|
||||
llvm::Function *FunctionVal;
|
||||
llvm::BasicBlock *BasicBlockVal;
|
||||
@ -43,135 +341,14 @@ typedef union {
|
||||
llvm::ICmpInst::Predicate IPredicate;
|
||||
llvm::FCmpInst::Predicate FPredicate;
|
||||
} YYSTYPE;
|
||||
#define ESINT64VAL 257
|
||||
#define EUINT64VAL 258
|
||||
#define LOCALVAL_ID 259
|
||||
#define GLOBALVAL_ID 260
|
||||
#define FPVAL 261
|
||||
#define VOID 262
|
||||
#define INTTYPE 263
|
||||
#define FLOAT 264
|
||||
#define DOUBLE 265
|
||||
#define LABEL 266
|
||||
#define TYPE 267
|
||||
#define LOCALVAR 268
|
||||
#define GLOBALVAR 269
|
||||
#define LABELSTR 270
|
||||
#define STRINGCONSTANT 271
|
||||
#define ATSTRINGCONSTANT 272
|
||||
#define IMPLEMENTATION 273
|
||||
#define ZEROINITIALIZER 274
|
||||
#define TRUETOK 275
|
||||
#define FALSETOK 276
|
||||
#define BEGINTOK 277
|
||||
#define ENDTOK 278
|
||||
#define DECLARE 279
|
||||
#define DEFINE 280
|
||||
#define GLOBAL 281
|
||||
#define CONSTANT 282
|
||||
#define SECTION 283
|
||||
#define VOLATILE 284
|
||||
#define TO 285
|
||||
#define DOTDOTDOT 286
|
||||
#define NULL_TOK 287
|
||||
#define UNDEF 288
|
||||
#define INTERNAL 289
|
||||
#define LINKONCE 290
|
||||
#define WEAK 291
|
||||
#define APPENDING 292
|
||||
#define DLLIMPORT 293
|
||||
#define DLLEXPORT 294
|
||||
#define EXTERN_WEAK 295
|
||||
#define OPAQUE 296
|
||||
#define EXTERNAL 297
|
||||
#define TARGET 298
|
||||
#define TRIPLE 299
|
||||
#define ALIGN 300
|
||||
#define DEPLIBS 301
|
||||
#define CALL 302
|
||||
#define TAIL 303
|
||||
#define ASM_TOK 304
|
||||
#define MODULE 305
|
||||
#define SIDEEFFECT 306
|
||||
#define CC_TOK 307
|
||||
#define CCC_TOK 308
|
||||
#define FASTCC_TOK 309
|
||||
#define COLDCC_TOK 310
|
||||
#define X86_STDCALLCC_TOK 311
|
||||
#define X86_FASTCALLCC_TOK 312
|
||||
#define DATALAYOUT 313
|
||||
#define RET 314
|
||||
#define BR 315
|
||||
#define SWITCH 316
|
||||
#define INVOKE 317
|
||||
#define UNWIND 318
|
||||
#define UNREACHABLE 319
|
||||
#define ADD 320
|
||||
#define SUB 321
|
||||
#define MUL 322
|
||||
#define UDIV 323
|
||||
#define SDIV 324
|
||||
#define FDIV 325
|
||||
#define UREM 326
|
||||
#define SREM 327
|
||||
#define FREM 328
|
||||
#define AND 329
|
||||
#define OR 330
|
||||
#define XOR 331
|
||||
#define ICMP 332
|
||||
#define FCMP 333
|
||||
#define EQ 334
|
||||
#define NE 335
|
||||
#define SLT 336
|
||||
#define SGT 337
|
||||
#define SLE 338
|
||||
#define SGE 339
|
||||
#define ULT 340
|
||||
#define UGT 341
|
||||
#define ULE 342
|
||||
#define UGE 343
|
||||
#define OEQ 344
|
||||
#define ONE 345
|
||||
#define OLT 346
|
||||
#define OGT 347
|
||||
#define OLE 348
|
||||
#define OGE 349
|
||||
#define ORD 350
|
||||
#define UNO 351
|
||||
#define UEQ 352
|
||||
#define UNE 353
|
||||
#define MALLOC 354
|
||||
#define ALLOCA 355
|
||||
#define FREE 356
|
||||
#define LOAD 357
|
||||
#define STORE 358
|
||||
#define GETELEMENTPTR 359
|
||||
#define TRUNC 360
|
||||
#define ZEXT 361
|
||||
#define SEXT 362
|
||||
#define FPTRUNC 363
|
||||
#define FPEXT 364
|
||||
#define BITCAST 365
|
||||
#define UITOFP 366
|
||||
#define SITOFP 367
|
||||
#define FPTOUI 368
|
||||
#define FPTOSI 369
|
||||
#define INTTOPTR 370
|
||||
#define PTRTOINT 371
|
||||
#define PHI_TOK 372
|
||||
#define SELECT 373
|
||||
#define SHL 374
|
||||
#define LSHR 375
|
||||
#define ASHR 376
|
||||
#define VAARG 377
|
||||
#define EXTRACTELEMENT 378
|
||||
#define INSERTELEMENT 379
|
||||
#define SHUFFLEVECTOR 380
|
||||
#define NORETURN 381
|
||||
#define INREG 382
|
||||
#define SRET 383
|
||||
#define DEFAULT 384
|
||||
#define HIDDEN 385
|
||||
|
||||
/* Line 1447 of yacc.c. */
|
||||
#line 346 "llvmAsmParser.tab.h"
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
extern YYSTYPE llvmAsmlval;
|
||||
|
||||
|
||||
|
||||
|
@ -997,6 +997,8 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
// Binary Operators
|
||||
%type <BinaryOpVal> ArithmeticOps LogicalOps // Binops Subcatagories
|
||||
%token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
|
||||
%token <BinaryOpVal> SHL LSHR ASHR
|
||||
|
||||
%token <OtherOpVal> ICMP FCMP
|
||||
%type <IPredicate> IPredicates
|
||||
%type <FPredicate> FPredicates
|
||||
@ -1012,8 +1014,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
%token <CastOpVal> UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
|
||||
|
||||
// Other Operators
|
||||
%type <OtherOpVal> ShiftOps
|
||||
%token <OtherOpVal> PHI_TOK SELECT SHL LSHR ASHR VAARG
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
|
||||
// Function Attributes
|
||||
@ -1030,10 +1031,10 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
// RET, BR, & SWITCH because they end basic blocks and are treated specially.
|
||||
//
|
||||
ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
|
||||
LogicalOps : AND | OR | XOR;
|
||||
LogicalOps : SHL | LSHR | ASHR | AND | OR | XOR;
|
||||
CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST |
|
||||
UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
|
||||
ShiftOps : SHL | LSHR | ASHR;
|
||||
|
||||
IPredicates
|
||||
: EQ { $$ = ICmpInst::ICMP_EQ; } | NE { $$ = ICmpInst::ICMP_NE; }
|
||||
| SLT { $$ = ICmpInst::ICMP_SLT; } | SGT { $$ = ICmpInst::ICMP_SGT; }
|
||||
@ -1764,7 +1765,7 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
if ($3->getType() != $5->getType())
|
||||
GEN_ERROR("Logical operator types must match!");
|
||||
if (!$3->getType()->isInteger()) {
|
||||
if (!isa<PackedType>($3->getType()) ||
|
||||
if (Instruction::isShift($1) || !isa<PackedType>($3->getType()) ||
|
||||
!cast<PackedType>($3->getType())->getElementType()->isInteger())
|
||||
GEN_ERROR("Logical operator requires integral operands!");
|
||||
}
|
||||
@ -1781,15 +1782,6 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
GEN_ERROR("fcmp operand types must match!");
|
||||
$$ = ConstantExpr::getFCmp($2, $4, $6);
|
||||
}
|
||||
| ShiftOps '(' ConstVal ',' ConstVal ')' {
|
||||
if ($5->getType() != Type::Int8Ty)
|
||||
GEN_ERROR("Shift count for shift constant must be i8 type!");
|
||||
if (!$3->getType()->isInteger())
|
||||
GEN_ERROR("Shift constant expression requires integer operand!");
|
||||
CHECK_FOR_ERROR;
|
||||
$$ = ConstantExpr::get($1, $3, $5);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
|
||||
if (!ExtractElementInst::isValidOperands($3, $5))
|
||||
GEN_ERROR("Invalid extractelement operands!");
|
||||
@ -2592,7 +2584,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!(*$2)->isInteger()) {
|
||||
if (!isa<PackedType>($2->get()) ||
|
||||
if (Instruction::isShift($1) || !isa<PackedType>($2->get()) ||
|
||||
!cast<PackedType>($2->get())->getElementType()->isInteger())
|
||||
GEN_ERROR("Logical operator requires integral operands!");
|
||||
}
|
||||
@ -2631,15 +2623,6 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("fcmp operator returned null!");
|
||||
}
|
||||
| ShiftOps ResolvedVal ',' ResolvedVal {
|
||||
if ($4->getType() != Type::Int8Ty)
|
||||
GEN_ERROR("Shift amount must be i8 type!");
|
||||
if (!$2->getType()->isInteger())
|
||||
GEN_ERROR("Shift constant expression requires integer operand!");
|
||||
CHECK_FOR_ERROR;
|
||||
$$ = new ShiftInst($1, $2, $4);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| CastOps ResolvedVal TO Types {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
|
||||
|
@ -997,6 +997,8 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
// Binary Operators
|
||||
%type <BinaryOpVal> ArithmeticOps LogicalOps // Binops Subcatagories
|
||||
%token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
|
||||
%token <BinaryOpVal> SHL LSHR ASHR
|
||||
|
||||
%token <OtherOpVal> ICMP FCMP
|
||||
%type <IPredicate> IPredicates
|
||||
%type <FPredicate> FPredicates
|
||||
@ -1012,8 +1014,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
%token <CastOpVal> UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
|
||||
|
||||
// Other Operators
|
||||
%type <OtherOpVal> ShiftOps
|
||||
%token <OtherOpVal> PHI_TOK SELECT SHL LSHR ASHR VAARG
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
|
||||
// Function Attributes
|
||||
@ -1030,10 +1031,10 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
// RET, BR, & SWITCH because they end basic blocks and are treated specially.
|
||||
//
|
||||
ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
|
||||
LogicalOps : AND | OR | XOR;
|
||||
LogicalOps : SHL | LSHR | ASHR | AND | OR | XOR;
|
||||
CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST |
|
||||
UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
|
||||
ShiftOps : SHL | LSHR | ASHR;
|
||||
|
||||
IPredicates
|
||||
: EQ { $$ = ICmpInst::ICMP_EQ; } | NE { $$ = ICmpInst::ICMP_NE; }
|
||||
| SLT { $$ = ICmpInst::ICMP_SLT; } | SGT { $$ = ICmpInst::ICMP_SGT; }
|
||||
@ -1764,7 +1765,7 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
if ($3->getType() != $5->getType())
|
||||
GEN_ERROR("Logical operator types must match!");
|
||||
if (!$3->getType()->isInteger()) {
|
||||
if (!isa<PackedType>($3->getType()) ||
|
||||
if (Instruction::isShift($1) || !isa<PackedType>($3->getType()) ||
|
||||
!cast<PackedType>($3->getType())->getElementType()->isInteger())
|
||||
GEN_ERROR("Logical operator requires integral operands!");
|
||||
}
|
||||
@ -1781,15 +1782,6 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
GEN_ERROR("fcmp operand types must match!");
|
||||
$$ = ConstantExpr::getFCmp($2, $4, $6);
|
||||
}
|
||||
| ShiftOps '(' ConstVal ',' ConstVal ')' {
|
||||
if ($5->getType() != Type::Int8Ty)
|
||||
GEN_ERROR("Shift count for shift constant must be i8 type!");
|
||||
if (!$3->getType()->isInteger())
|
||||
GEN_ERROR("Shift constant expression requires integer operand!");
|
||||
CHECK_FOR_ERROR;
|
||||
$$ = ConstantExpr::get($1, $3, $5);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
|
||||
if (!ExtractElementInst::isValidOperands($3, $5))
|
||||
GEN_ERROR("Invalid extractelement operands!");
|
||||
@ -2592,7 +2584,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!(*$2)->isInteger()) {
|
||||
if (!isa<PackedType>($2->get()) ||
|
||||
if (Instruction::isShift($1) || !isa<PackedType>($2->get()) ||
|
||||
!cast<PackedType>($2->get())->getElementType()->isInteger())
|
||||
GEN_ERROR("Logical operator requires integral operands!");
|
||||
}
|
||||
@ -2631,15 +2623,6 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("fcmp operator returned null!");
|
||||
}
|
||||
| ShiftOps ResolvedVal ',' ResolvedVal {
|
||||
if ($4->getType() != Type::Int8Ty)
|
||||
GEN_ERROR("Shift amount must be i8 type!");
|
||||
if (!$2->getType()->isInteger())
|
||||
GEN_ERROR("Shift constant expression requires integer operand!");
|
||||
CHECK_FOR_ERROR;
|
||||
$$ = new ShiftInst($1, $2, $4);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| CastOps ResolvedVal TO Types {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
|
||||
|
@ -607,13 +607,6 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
|
||||
static_cast<unsigned short>(Oprnds[2]),
|
||||
getValue(iType, Oprnds[0]), getValue(iType, Oprnds[1]));
|
||||
break;
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
Result = new ShiftInst(Instruction::OtherOps(Opcode),
|
||||
getValue(iType, Oprnds[0]),
|
||||
getValue(Int8TySlot, Oprnds[1]));
|
||||
break;
|
||||
case Instruction::Ret:
|
||||
if (Oprnds.size() == 0)
|
||||
Result = new ReturnInst();
|
||||
|
@ -118,22 +118,22 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
|
||||
switch(BitSize) {
|
||||
default: assert(0 && "Unhandled type size of value to byteswap!");
|
||||
case 16: {
|
||||
Value *Tmp1 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.2",IP);
|
||||
Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.1",IP);
|
||||
Value *Tmp1 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.2",IP);
|
||||
Value *Tmp2 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.1",IP);
|
||||
V = BinaryOperator::createOr(Tmp1, Tmp2, "bswap.i16", IP);
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
Value *Tmp4 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,24),"bswap.4", IP);
|
||||
Value *Tmp3 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.3",IP);
|
||||
Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.2",IP);
|
||||
Value *Tmp1 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,24),"bswap.1", IP);
|
||||
Value *Tmp4 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),24),"bswap.4", IP);
|
||||
Value *Tmp3 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.3",IP);
|
||||
Value *Tmp2 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.2",IP);
|
||||
Value *Tmp1 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),24),"bswap.1", IP);
|
||||
Tmp3 = BinaryOperator::createAnd(Tmp3,
|
||||
ConstantInt::get(Type::Int32Ty, 0xFF0000),
|
||||
"bswap.and3", IP);
|
||||
@ -146,22 +146,22 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
|
||||
break;
|
||||
}
|
||||
case 64: {
|
||||
Value *Tmp8 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,56),"bswap.8", IP);
|
||||
Value *Tmp7 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,40),"bswap.7", IP);
|
||||
Value *Tmp6 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,24),"bswap.6", IP);
|
||||
Value *Tmp5 = new ShiftInst(Instruction::Shl, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.5", IP);
|
||||
Value* Tmp4 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,8),"bswap.4", IP);
|
||||
Value* Tmp3 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,24),"bswap.3", IP);
|
||||
Value* Tmp2 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,40),"bswap.2", IP);
|
||||
Value* Tmp1 = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty,56),"bswap.1", IP);
|
||||
Value *Tmp8 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),56),"bswap.8", IP);
|
||||
Value *Tmp7 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),40),"bswap.7", IP);
|
||||
Value *Tmp6 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),24),"bswap.6", IP);
|
||||
Value *Tmp5 = BinaryOperator::create(Instruction::Shl, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.5", IP);
|
||||
Value* Tmp4 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),8),"bswap.4", IP);
|
||||
Value* Tmp3 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),24),"bswap.3", IP);
|
||||
Value* Tmp2 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),40),"bswap.2", IP);
|
||||
Value* Tmp1 = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(),56),"bswap.1", IP);
|
||||
Tmp7 = BinaryOperator::createAnd(Tmp7,
|
||||
ConstantInt::get(Type::Int64Ty,
|
||||
0xFF000000000000ULL),
|
||||
@ -210,8 +210,8 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) {
|
||||
for (unsigned i = 1, ct = 0; i != BitSize; i <<= 1, ++ct) {
|
||||
Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
|
||||
Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP);
|
||||
Value *VShift = new ShiftInst(Instruction::LShr, V,
|
||||
ConstantInt::get(Type::Int8Ty, i), "ctpop.sh", IP);
|
||||
Value *VShift = BinaryOperator::create(Instruction::LShr, V,
|
||||
ConstantInt::get(V->getType(), i), "ctpop.sh", IP);
|
||||
Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP);
|
||||
V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP);
|
||||
}
|
||||
@ -225,8 +225,8 @@ static Value *LowerCTLZ(Value *V, Instruction *IP) {
|
||||
|
||||
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
|
||||
for (unsigned i = 1; i != BitSize; i <<= 1) {
|
||||
Value *ShVal = ConstantInt::get(Type::Int8Ty, i);
|
||||
ShVal = new ShiftInst(Instruction::LShr, V, ShVal, "ctlz.sh", IP);
|
||||
Value *ShVal = ConstantInt::get(V->getType(), i);
|
||||
ShVal = BinaryOperator::create(Instruction::LShr, V, ShVal, "ctlz.sh", IP);
|
||||
V = BinaryOperator::createOr(V, ShVal, "ctlz.step", IP);
|
||||
}
|
||||
|
||||
|
@ -1420,7 +1420,10 @@ void SelectionDAGLowering::visitShift(User &I, unsigned Opcode) {
|
||||
SDOperand Op1 = getValue(I.getOperand(0));
|
||||
SDOperand Op2 = getValue(I.getOperand(1));
|
||||
|
||||
Op2 = DAG.getNode(ISD::ANY_EXTEND, TLI.getShiftAmountTy(), Op2);
|
||||
if (TLI.getShiftAmountTy() < Op2.getValueType())
|
||||
Op2 = DAG.getNode(ISD::TRUNCATE, TLI.getShiftAmountTy(), Op2);
|
||||
else if (TLI.getShiftAmountTy() > Op2.getValueType())
|
||||
Op2 = DAG.getNode(ISD::ANY_EXTEND, TLI.getShiftAmountTy(), Op2);
|
||||
|
||||
setValue(&I, DAG.getNode(Opcode, Op1.getValueType(), Op1, Op2));
|
||||
}
|
||||
|
@ -1275,7 +1275,7 @@ static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2,
|
||||
return Dest;
|
||||
}
|
||||
|
||||
void Interpreter::visitShl(ShiftInst &I) {
|
||||
void Interpreter::visitShl(BinaryOperator &I) {
|
||||
ExecutionContext &SF = ECStack.back();
|
||||
const Type *Ty = I.getOperand(0)->getType();
|
||||
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
|
||||
@ -1285,7 +1285,7 @@ void Interpreter::visitShl(ShiftInst &I) {
|
||||
SetValue(&I, Dest, SF);
|
||||
}
|
||||
|
||||
void Interpreter::visitLShr(ShiftInst &I) {
|
||||
void Interpreter::visitLShr(BinaryOperator &I) {
|
||||
ExecutionContext &SF = ECStack.back();
|
||||
const Type *Ty = I.getOperand(0)->getType();
|
||||
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
|
||||
@ -1295,7 +1295,7 @@ void Interpreter::visitLShr(ShiftInst &I) {
|
||||
SetValue(&I, Dest, SF);
|
||||
}
|
||||
|
||||
void Interpreter::visitAShr(ShiftInst &I) {
|
||||
void Interpreter::visitAShr(BinaryOperator &I) {
|
||||
ExecutionContext &SF = ECStack.back();
|
||||
const Type *Ty = I.getOperand(0)->getType();
|
||||
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
|
||||
|
@ -165,9 +165,10 @@ public:
|
||||
void visitUnwindInst(UnwindInst &I);
|
||||
void visitUnreachableInst(UnreachableInst &I);
|
||||
|
||||
void visitShl(ShiftInst &I);
|
||||
void visitLShr(ShiftInst &I);
|
||||
void visitAShr(ShiftInst &I);
|
||||
void visitShl(BinaryOperator &I);
|
||||
void visitLShr(BinaryOperator &I);
|
||||
void visitAShr(BinaryOperator &I);
|
||||
|
||||
void visitVAArgInst(VAArgInst &I);
|
||||
void visitInstruction(Instruction &I) {
|
||||
cerr << I;
|
||||
|
@ -8,7 +8,7 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
LEVEL = ..
|
||||
|
||||
PARALLEL_DIRS = VMCore Analysis Transforms AsmParser Bytecode CodeGen Target \
|
||||
PARALLEL_DIRS = VMCore AsmParser Bytecode Analysis Transforms CodeGen Target \
|
||||
ExecutionEngine Debugger Linker
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
@ -225,7 +225,6 @@ namespace {
|
||||
void visitSelectInst(SelectInst &I);
|
||||
void visitCallInst (CallInst &I);
|
||||
void visitInlineAsm(CallInst &I);
|
||||
void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
|
||||
|
||||
void visitMallocInst(MallocInst &I);
|
||||
void visitAllocaInst(AllocaInst &I);
|
||||
@ -2160,18 +2159,18 @@ void CWriter::visitBinaryOperator(Instruction &I) {
|
||||
writeOperandWithCast(I.getOperand(0), I.getOpcode());
|
||||
|
||||
switch (I.getOpcode()) {
|
||||
case Instruction::Add: Out << " + "; break;
|
||||
case Instruction::Sub: Out << " - "; break;
|
||||
case Instruction::Mul: Out << '*'; break;
|
||||
case Instruction::Add: Out << " + "; break;
|
||||
case Instruction::Sub: Out << " - "; break;
|
||||
case Instruction::Mul: Out << " * "; break;
|
||||
case Instruction::URem:
|
||||
case Instruction::SRem:
|
||||
case Instruction::FRem: Out << '%'; break;
|
||||
case Instruction::FRem: Out << " % "; break;
|
||||
case Instruction::UDiv:
|
||||
case Instruction::SDiv:
|
||||
case Instruction::FDiv: Out << '/'; break;
|
||||
case Instruction::And: Out << " & "; break;
|
||||
case Instruction::Or: Out << " | "; break;
|
||||
case Instruction::Xor: Out << " ^ "; break;
|
||||
case Instruction::FDiv: Out << " / "; break;
|
||||
case Instruction::And: Out << " & "; break;
|
||||
case Instruction::Or: Out << " | "; break;
|
||||
case Instruction::Xor: Out << " ^ "; break;
|
||||
case Instruction::Shl : Out << " << "; break;
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr: Out << " >> "; break;
|
||||
|
@ -251,8 +251,8 @@ Value *llvm::ConvertExpressionToType(Value *V, const Type *Ty,
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
Res = new ShiftInst(cast<ShiftInst>(I)->getOpcode(), Dummy,
|
||||
I->getOperand(1), Name);
|
||||
Res = BinaryOperator::create(cast<BinaryOperator>(I)->getOpcode(), Dummy,
|
||||
I->getOperand(1), Name);
|
||||
VMC.ExprMap[I] = Res;
|
||||
Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), Ty, VMC, TD));
|
||||
break;
|
||||
@ -472,9 +472,9 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
case Instruction::Shl:
|
||||
if (I->getOperand(1) == V) return false; // Cannot change shift amount type
|
||||
if (!Ty->isInteger()) return false;
|
||||
return ValueConvertibleToType(I, Ty, CTMap, TD);
|
||||
@ -747,8 +747,8 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
assert(I->getOperand(0) == OldVal);
|
||||
Res = new ShiftInst(cast<ShiftInst>(I)->getOpcode(), NewVal,
|
||||
I->getOperand(1), Name);
|
||||
Res = BinaryOperator::create(cast<BinaryOperator>(I)->getOpcode(), NewVal,
|
||||
I->getOperand(1), Name);
|
||||
break;
|
||||
|
||||
case Instruction::Free: // Free can free any pointer type!
|
||||
|
@ -1728,10 +1728,6 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
||||
InstResult = ConstantExpr::get(BO->getOpcode(),
|
||||
getVal(Values, BO->getOperand(0)),
|
||||
getVal(Values, BO->getOperand(1)));
|
||||
} else if (ShiftInst *SI = dyn_cast<ShiftInst>(CurInst)) {
|
||||
InstResult = ConstantExpr::get(SI->getOpcode(),
|
||||
getVal(Values, SI->getOperand(0)),
|
||||
getVal(Values, SI->getOperand(1)));
|
||||
} else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) {
|
||||
InstResult = ConstantExpr::getCompare(CI->getPredicate(),
|
||||
getVal(Values, CI->getOperand(0)),
|
||||
|
@ -145,15 +145,18 @@ namespace {
|
||||
Instruction *visitAnd(BinaryOperator &I);
|
||||
Instruction *visitOr (BinaryOperator &I);
|
||||
Instruction *visitXor(BinaryOperator &I);
|
||||
Instruction *visitShl(BinaryOperator &I);
|
||||
Instruction *visitAShr(BinaryOperator &I);
|
||||
Instruction *visitLShr(BinaryOperator &I);
|
||||
Instruction *commonShiftTransforms(BinaryOperator &I);
|
||||
Instruction *visitFCmpInst(FCmpInst &I);
|
||||
Instruction *visitICmpInst(ICmpInst &I);
|
||||
Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI);
|
||||
|
||||
Instruction *FoldGEPICmp(User *GEPLHS, Value *RHS,
|
||||
ICmpInst::Predicate Cond, Instruction &I);
|
||||
Instruction *visitShiftInst(ShiftInst &I);
|
||||
Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
ShiftInst &I);
|
||||
BinaryOperator &I);
|
||||
Instruction *commonCastTransforms(CastInst &CI);
|
||||
Instruction *commonIntCastTransforms(CastInst &CI);
|
||||
Instruction *visitTrunc(CastInst &CI);
|
||||
@ -1197,8 +1200,8 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
|
||||
// the shift amount is >= the size of the datatype, which is undefined.
|
||||
if (DemandedMask == 1) {
|
||||
// Perform the logical shift right.
|
||||
Value *NewVal = new ShiftInst(Instruction::LShr, I->getOperand(0),
|
||||
I->getOperand(1), I->getName());
|
||||
Value *NewVal = BinaryOperator::create(Instruction::LShr,
|
||||
I->getOperand(0), I->getOperand(1), I->getName());
|
||||
InsertNewInstBefore(cast<Instruction>(NewVal), *I);
|
||||
return UpdateValueUsesWith(I, NewVal);
|
||||
}
|
||||
@ -1229,8 +1232,8 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
|
||||
// are demanded, turn this into an unsigned shift right.
|
||||
if ((KnownZero & SignBit) || (HighBits & ~DemandedMask) == HighBits) {
|
||||
// Perform the logical shift right.
|
||||
Value *NewVal = new ShiftInst(Instruction::LShr, I->getOperand(0),
|
||||
SA, I->getName());
|
||||
Value *NewVal = BinaryOperator::create(Instruction::LShr,
|
||||
I->getOperand(0), SA, I->getName());
|
||||
InsertNewInstBefore(cast<Instruction>(NewVal), *I);
|
||||
return UpdateValueUsesWith(I, NewVal);
|
||||
} else if (KnownOne & SignBit) { // New bits are known one.
|
||||
@ -1546,8 +1549,8 @@ struct AddRHS {
|
||||
AddRHS(Value *rhs) : RHS(rhs) {}
|
||||
bool shouldApply(Value *LHS) const { return LHS == RHS; }
|
||||
Instruction *apply(BinaryOperator &Add) const {
|
||||
return new ShiftInst(Instruction::Shl, Add.getOperand(0),
|
||||
ConstantInt::get(Type::Int8Ty, 1));
|
||||
return BinaryOperator::create(Instruction::Shl, Add.getOperand(0),
|
||||
ConstantInt::get(Add.getType(), 1));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1595,8 +1598,6 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
||||
else if (CmpInst *CI = dyn_cast<CmpInst>(&I))
|
||||
New = CmpInst::create(CI->getOpcode(), CI->getPredicate(), Op0, Op1,
|
||||
SO->getName()+".cmp");
|
||||
else if (ShiftInst *SI = dyn_cast<ShiftInst>(&I))
|
||||
New = new ShiftInst(SI->getOpcode(), Op0, Op1, SO->getName()+".sh");
|
||||
else {
|
||||
assert(0 && "Unknown binary instruction type!");
|
||||
abort();
|
||||
@ -1688,10 +1689,6 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
|
||||
CI->getPredicate(),
|
||||
PN->getIncomingValue(i), C, "phitmp",
|
||||
NonConstBB->getTerminator());
|
||||
else if (ShiftInst *SI = dyn_cast<ShiftInst>(&I))
|
||||
InV = new ShiftInst(SI->getOpcode(),
|
||||
PN->getIncomingValue(i), C, "phitmp",
|
||||
NonConstBB->getTerminator());
|
||||
else
|
||||
assert(0 && "Unknown binop!");
|
||||
|
||||
@ -1958,15 +1955,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
// -(X >>u 31) -> (X >>s 31)
|
||||
// -(X >>s 31) -> (X >>u 31)
|
||||
if (C->isNullValue()) {
|
||||
if (ShiftInst *SI = dyn_cast<ShiftInst>(Op1))
|
||||
if (BinaryOperator *SI = dyn_cast<BinaryOperator>(Op1))
|
||||
if (SI->getOpcode() == Instruction::LShr) {
|
||||
if (ConstantInt *CU = dyn_cast<ConstantInt>(SI->getOperand(1))) {
|
||||
// Check to see if we are shifting out everything but the sign bit.
|
||||
if (CU->getZExtValue() ==
|
||||
SI->getType()->getPrimitiveSizeInBits()-1) {
|
||||
// Ok, the transformation is safe. Insert AShr.
|
||||
return new ShiftInst(Instruction::AShr, SI->getOperand(0), CU,
|
||||
SI->getName());
|
||||
return BinaryOperator::create(Instruction::AShr,
|
||||
SI->getOperand(0), CU, SI->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1976,8 +1973,8 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
if (CU->getZExtValue() ==
|
||||
SI->getType()->getPrimitiveSizeInBits()-1) {
|
||||
// Ok, the transformation is safe. Insert LShr.
|
||||
return new ShiftInst(Instruction::LShr, SI->getOperand(0), CU,
|
||||
SI->getName());
|
||||
return BinaryOperator::create(Instruction::LShr,
|
||||
SI->getOperand(0), CU, SI->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2113,7 +2110,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
|
||||
|
||||
// ((X << C1)*C2) == (X * (C2 << C1))
|
||||
if (ShiftInst *SI = dyn_cast<ShiftInst>(Op0))
|
||||
if (BinaryOperator *SI = dyn_cast<BinaryOperator>(Op0))
|
||||
if (SI->getOpcode() == Instruction::Shl)
|
||||
if (Constant *ShOp = dyn_cast<Constant>(SI->getOperand(1)))
|
||||
return BinaryOperator::createMul(SI->getOperand(0),
|
||||
@ -2129,8 +2126,8 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
int64_t Val = (int64_t)cast<ConstantInt>(CI)->getZExtValue();
|
||||
if (isPowerOf2_64(Val)) { // Replace X*(2^C) with X << C
|
||||
uint64_t C = Log2_64(Val);
|
||||
return new ShiftInst(Instruction::Shl, Op0,
|
||||
ConstantInt::get(Type::Int8Ty, C));
|
||||
return BinaryOperator::create(Instruction::Shl, Op0,
|
||||
ConstantInt::get(Op0->getType(), C));
|
||||
}
|
||||
} else if (ConstantFP *Op1F = dyn_cast<ConstantFP>(Op1)) {
|
||||
if (Op1F->isNullValue())
|
||||
@ -2191,10 +2188,11 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
if (isa<ConstantInt>(SCIOp1) &&
|
||||
isSignBitCheck(SCI->getPredicate(), cast<ConstantInt>(SCIOp1))) {
|
||||
// Shift the X value right to turn it into "all signbits".
|
||||
Constant *Amt = ConstantInt::get(Type::Int8Ty,
|
||||
Constant *Amt = ConstantInt::get(SCIOp0->getType(),
|
||||
SCOpTy->getPrimitiveSizeInBits()-1);
|
||||
Value *V =
|
||||
InsertNewInstBefore(new ShiftInst(Instruction::AShr, SCIOp0, Amt,
|
||||
InsertNewInstBefore(
|
||||
BinaryOperator::create(Instruction::AShr, SCIOp0, Amt,
|
||||
BoolCast->getOperand(0)->getName()+
|
||||
".mask"), I);
|
||||
|
||||
@ -2324,13 +2322,13 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
if (uint64_t Val = C->getZExtValue()) // Don't break X / 0
|
||||
if (isPowerOf2_64(Val)) {
|
||||
uint64_t ShiftAmt = Log2_64(Val);
|
||||
return new ShiftInst(Instruction::LShr, Op0,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt));
|
||||
return BinaryOperator::create(Instruction::LShr, Op0,
|
||||
ConstantInt::get(Op0->getType(), ShiftAmt));
|
||||
}
|
||||
}
|
||||
|
||||
// X udiv (C1 << N), where C1 is "1<<C2" --> X >> (N+C2)
|
||||
if (ShiftInst *RHSI = dyn_cast<ShiftInst>(I.getOperand(1))) {
|
||||
if (BinaryOperator *RHSI = dyn_cast<BinaryOperator>(I.getOperand(1))) {
|
||||
if (RHSI->getOpcode() == Instruction::Shl &&
|
||||
isa<ConstantInt>(RHSI->getOperand(0))) {
|
||||
uint64_t C1 = cast<ConstantInt>(RHSI->getOperand(0))->getZExtValue();
|
||||
@ -2341,7 +2339,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
Constant *C2V = ConstantInt::get(NTy, C2);
|
||||
N = InsertNewInstBefore(BinaryOperator::createAdd(N, C2V, "tmp"), I);
|
||||
}
|
||||
return new ShiftInst(Instruction::LShr, Op0, N);
|
||||
return BinaryOperator::create(Instruction::LShr, Op0, N);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2357,15 +2355,15 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
// Compute the shift amounts
|
||||
unsigned TSA = Log2_64(TVA), FSA = Log2_64(FVA);
|
||||
// Construct the "on true" case of the select
|
||||
Constant *TC = ConstantInt::get(Type::Int8Ty, TSA);
|
||||
Instruction *TSI =
|
||||
new ShiftInst(Instruction::LShr, Op0, TC, SI->getName()+".t");
|
||||
Constant *TC = ConstantInt::get(Op0->getType(), TSA);
|
||||
Instruction *TSI = BinaryOperator::create(Instruction::LShr,
|
||||
Op0, TC, SI->getName()+".t");
|
||||
TSI = InsertNewInstBefore(TSI, I);
|
||||
|
||||
// Construct the "on false" case of the select
|
||||
Constant *FC = ConstantInt::get(Type::Int8Ty, FSA);
|
||||
Instruction *FSI =
|
||||
new ShiftInst(Instruction::LShr, Op0, FC, SI->getName()+".f");
|
||||
Constant *FC = ConstantInt::get(Op0->getType(), FSA);
|
||||
Instruction *FSI = BinaryOperator::create(Instruction::LShr,
|
||||
Op0, FC, SI->getName()+".f");
|
||||
FSI = InsertNewInstBefore(FSI, I);
|
||||
|
||||
// construct the select instruction and return it.
|
||||
@ -2437,7 +2435,7 @@ static Constant *GetFactor(Value *V) {
|
||||
unsigned Zeros = CountTrailingZeros_64(RHS->getZExtValue());
|
||||
if (Zeros != V->getType()->getPrimitiveSizeInBits())
|
||||
return ConstantExpr::getShl(Result,
|
||||
ConstantInt::get(Type::Int8Ty, Zeros));
|
||||
ConstantInt::get(Result->getType(), Zeros));
|
||||
}
|
||||
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
|
||||
// Only handle int->int casts.
|
||||
@ -2801,14 +2799,14 @@ struct FoldICmpLogical {
|
||||
|
||||
// OptAndOp - This handles expressions of the form ((val OP C1) & C2). Where
|
||||
// the Op parameter is 'OP', OpRHS is 'C1', and AndRHS is 'C2'. Op is
|
||||
// guaranteed to be either a shift instruction or a binary operator.
|
||||
// guaranteed to be a binary operator.
|
||||
Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
||||
ConstantInt *OpRHS,
|
||||
ConstantInt *AndRHS,
|
||||
BinaryOperator &TheAnd) {
|
||||
Value *X = Op->getOperand(0);
|
||||
Constant *Together = 0;
|
||||
if (!isa<ShiftInst>(Op))
|
||||
if (!Op->isShift())
|
||||
Together = ConstantExpr::getAnd(AndRHS, OpRHS);
|
||||
|
||||
switch (Op->getOpcode()) {
|
||||
@ -2917,8 +2915,9 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
||||
// (Val ashr C1) & C2 -> (Val lshr C1) & C2
|
||||
// Make the argument unsigned.
|
||||
Value *ShVal = Op->getOperand(0);
|
||||
ShVal = InsertNewInstBefore(new ShiftInst(Instruction::LShr, ShVal,
|
||||
OpRHS, Op->getName()), TheAnd);
|
||||
ShVal = InsertNewInstBefore(
|
||||
BinaryOperator::create(Instruction::LShr, ShVal, OpRHS,
|
||||
Op->getName()), TheAnd);
|
||||
return BinaryOperator::createAnd(ShVal, AndRHS, TheAnd.getName());
|
||||
}
|
||||
}
|
||||
@ -3082,7 +3081,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
uint64_t NotAndRHS = AndRHSMask^TypeMask;
|
||||
|
||||
// Optimize a variety of ((val OP C1) & C2) combinations...
|
||||
if (isa<BinaryOperator>(Op0) || isa<ShiftInst>(Op0)) {
|
||||
if (isa<BinaryOperator>(Op0)) {
|
||||
Instruction *Op0I = cast<Instruction>(Op0);
|
||||
Value *Op0LHS = Op0I->getOperand(0);
|
||||
Value *Op0RHS = Op0I->getOperand(1);
|
||||
@ -3391,16 +3390,17 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
}
|
||||
|
||||
// (X >> Z) & (Y >> Z) -> (X&Y) >> Z for all shifts.
|
||||
if (ShiftInst *SI1 = dyn_cast<ShiftInst>(Op1)) {
|
||||
if (ShiftInst *SI0 = dyn_cast<ShiftInst>(Op0))
|
||||
if (SI0->getOpcode() == SI1->getOpcode() &&
|
||||
if (BinaryOperator *SI1 = dyn_cast<BinaryOperator>(Op1)) {
|
||||
if (BinaryOperator *SI0 = dyn_cast<BinaryOperator>(Op0))
|
||||
if (SI0->isShift() && SI0->getOpcode() == SI1->getOpcode() &&
|
||||
SI0->getOperand(1) == SI1->getOperand(1) &&
|
||||
(SI0->hasOneUse() || SI1->hasOneUse())) {
|
||||
Instruction *NewOp =
|
||||
InsertNewInstBefore(BinaryOperator::createAnd(SI0->getOperand(0),
|
||||
SI1->getOperand(0),
|
||||
SI0->getName()), I);
|
||||
return new ShiftInst(SI1->getOpcode(), NewOp, SI1->getOperand(1));
|
||||
return BinaryOperator::create(SI1->getOpcode(), NewOp,
|
||||
SI1->getOperand(1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3421,7 +3421,7 @@ static bool CollectBSwapParts(Value *V, std::vector<Value*> &ByteValues) {
|
||||
|
||||
// If this is a shift by a constant int, and it is "24", then its operand
|
||||
// defines a byte. We only handle unsigned types here.
|
||||
if (isa<ShiftInst>(I) && isa<ConstantInt>(I->getOperand(1))) {
|
||||
if (I->isShift() && isa<ConstantInt>(I->getOperand(1))) {
|
||||
// Not shifting the entire input by N-1 bytes?
|
||||
if (cast<ConstantInt>(I->getOperand(1))->getZExtValue() !=
|
||||
8*(ByteValues.size()-1))
|
||||
@ -3488,7 +3488,7 @@ static bool CollectBSwapParts(Value *V, std::vector<Value*> &ByteValues) {
|
||||
/// MatchBSwap - Given an OR instruction, check to see if this is a bswap idiom.
|
||||
/// If so, insert the new bswap intrinsic and return it.
|
||||
Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) {
|
||||
// We can only handle bswap of unsigned integers, and cannot bswap one byte.
|
||||
// We cannot bswap one byte.
|
||||
if (I.getType() == Type::Int8Ty)
|
||||
return 0;
|
||||
|
||||
@ -3647,16 +3647,17 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
}
|
||||
|
||||
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
|
||||
if (ShiftInst *SI1 = dyn_cast<ShiftInst>(Op1)) {
|
||||
if (ShiftInst *SI0 = dyn_cast<ShiftInst>(Op0))
|
||||
if (SI0->getOpcode() == SI1->getOpcode() &&
|
||||
if (BinaryOperator *SI1 = dyn_cast<BinaryOperator>(Op1)) {
|
||||
if (BinaryOperator *SI0 = dyn_cast<BinaryOperator>(Op0))
|
||||
if (SI0->isShift() && SI0->getOpcode() == SI1->getOpcode() &&
|
||||
SI0->getOperand(1) == SI1->getOperand(1) &&
|
||||
(SI0->hasOneUse() || SI1->hasOneUse())) {
|
||||
Instruction *NewOp =
|
||||
InsertNewInstBefore(BinaryOperator::createOr(SI0->getOperand(0),
|
||||
SI1->getOperand(0),
|
||||
SI0->getName()), I);
|
||||
return new ShiftInst(SI1->getOpcode(), NewOp, SI1->getOperand(1));
|
||||
return BinaryOperator::create(SI1->getOpcode(), NewOp,
|
||||
SI1->getOperand(1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -4025,16 +4026,17 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
}
|
||||
|
||||
// (X >> Z) ^ (Y >> Z) -> (X^Y) >> Z for all shifts.
|
||||
if (ShiftInst *SI1 = dyn_cast<ShiftInst>(Op1)) {
|
||||
if (ShiftInst *SI0 = dyn_cast<ShiftInst>(Op0))
|
||||
if (SI0->getOpcode() == SI1->getOpcode() &&
|
||||
if (BinaryOperator *SI1 = dyn_cast<BinaryOperator>(Op1)) {
|
||||
if (BinaryOperator *SI0 = dyn_cast<BinaryOperator>(Op0))
|
||||
if (SI0->isShift() && SI0->getOpcode() == SI1->getOpcode() &&
|
||||
SI0->getOperand(1) == SI1->getOperand(1) &&
|
||||
(SI0->hasOneUse() || SI1->hasOneUse())) {
|
||||
Instruction *NewOp =
|
||||
InsertNewInstBefore(BinaryOperator::createXor(SI0->getOperand(0),
|
||||
SI1->getOperand(0),
|
||||
SI0->getName()), I);
|
||||
return new ShiftInst(SI1->getOpcode(), NewOp, SI1->getOperand(1));
|
||||
return BinaryOperator::create(SI1->getOpcode(), NewOp,
|
||||
SI1->getOperand(1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -4599,13 +4601,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// could exist), turn it into (X & (C2 << C1)) != (C3 << C1). This
|
||||
// happens a LOT in code produced by the C front-end, for bitfield
|
||||
// access.
|
||||
ShiftInst *Shift = dyn_cast<ShiftInst>(LHSI->getOperand(0));
|
||||
BinaryOperator *Shift = dyn_cast<BinaryOperator>(LHSI->getOperand(0));
|
||||
if (Shift && !Shift->isShift())
|
||||
Shift = 0;
|
||||
|
||||
// Check to see if there is a noop-cast between the shift and the and.
|
||||
if (!Shift) {
|
||||
if (CastInst *CI = dyn_cast<CastInst>(LHSI->getOperand(0)))
|
||||
if (CI->getOpcode() == Instruction::BitCast)
|
||||
Shift = dyn_cast<ShiftInst>(CI->getOperand(0));
|
||||
if (CI->getOpcode() == Instruction::BitCast) {
|
||||
Shift = dyn_cast<BinaryOperator>(CI->getOperand(0));
|
||||
if (Shift && !Shift->isShift())
|
||||
Shift = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ConstantInt *ShAmt;
|
||||
@ -4624,7 +4631,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
int ShAmtVal = Ty->getPrimitiveSizeInBits()-ShAmt->getZExtValue();
|
||||
if (ShAmtVal < 0) ShAmtVal = 0; // Out of range shift.
|
||||
|
||||
Constant *OShAmt = ConstantInt::get(Type::Int8Ty, ShAmtVal);
|
||||
Constant *OShAmt = ConstantInt::get(AndTy, ShAmtVal);
|
||||
Constant *ShVal =
|
||||
ConstantExpr::getShl(ConstantInt::getAllOnesValue(AndTy),
|
||||
OShAmt);
|
||||
@ -4674,12 +4681,12 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// Compute C << Y.
|
||||
Value *NS;
|
||||
if (Shift->getOpcode() == Instruction::LShr) {
|
||||
NS = new ShiftInst(Instruction::Shl, AndCST, Shift->getOperand(1),
|
||||
"tmp");
|
||||
NS = BinaryOperator::create(Instruction::Shl, AndCST,
|
||||
Shift->getOperand(1), "tmp");
|
||||
} else {
|
||||
// Insert a logical shift.
|
||||
NS = new ShiftInst(Instruction::LShr, AndCST,
|
||||
Shift->getOperand(1), "tmp");
|
||||
NS = BinaryOperator::create(Instruction::LShr, AndCST,
|
||||
Shift->getOperand(1), "tmp");
|
||||
}
|
||||
InsertNewInstBefore(cast<Instruction>(NS), I);
|
||||
|
||||
@ -5368,13 +5375,25 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
||||
}
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
|
||||
assert(I.getOperand(1)->getType() == Type::Int8Ty);
|
||||
Instruction *InstCombiner::visitShl(BinaryOperator &I) {
|
||||
return commonShiftTransforms(I);
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
|
||||
return commonShiftTransforms(I);
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitAShr(BinaryOperator &I) {
|
||||
return commonShiftTransforms(I);
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) {
|
||||
assert(I.getOperand(1)->getType() == I.getOperand(0)->getType());
|
||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||
|
||||
// shl X, 0 == X and shr X, 0 == X
|
||||
// shl 0, X == 0 and shr 0, X == 0
|
||||
if (Op1 == Constant::getNullValue(Type::Int8Ty) ||
|
||||
if (Op1 == Constant::getNullValue(Op1->getType()) ||
|
||||
Op0 == Constant::getNullValue(Op0->getType()))
|
||||
return ReplaceInstUsesWith(I, Op0);
|
||||
|
||||
@ -5407,7 +5426,7 @@ Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
|
||||
if (I.isArithmeticShift()) {
|
||||
if (MaskedValueIsZero(Op0,
|
||||
1ULL << (I.getType()->getPrimitiveSizeInBits()-1))) {
|
||||
return new ShiftInst(Instruction::LShr, Op0, Op1, I.getName());
|
||||
return BinaryOperator::create(Instruction::LShr, Op0, Op1, I.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -5418,7 +5437,7 @@ Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
ShiftInst &I) {
|
||||
BinaryOperator &I) {
|
||||
bool isLeftShift = I.getOpcode() == Instruction::Shl;
|
||||
bool isSignedShift = I.getOpcode() == Instruction::AShr;
|
||||
bool isUnsignedShift = !isSignedShift;
|
||||
@ -5474,7 +5493,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
if (isLeftShift && Op0BO->getOperand(1)->hasOneUse() &&
|
||||
match(Op0BO->getOperand(1),
|
||||
m_Shr(m_Value(V1), m_ConstantInt(CC))) && CC == Op1) {
|
||||
Instruction *YS = new ShiftInst(Instruction::Shl,
|
||||
Instruction *YS = BinaryOperator::create(Instruction::Shl,
|
||||
Op0BO->getOperand(0), Op1,
|
||||
Op0BO->getName());
|
||||
InsertNewInstBefore(YS, I); // (Y << C)
|
||||
@ -5489,13 +5508,12 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
|
||||
// Turn (Y + ((X >> C) & CC)) << C -> ((X & (CC << C)) + (Y << C))
|
||||
if (isLeftShift && Op0BO->getOperand(1)->hasOneUse() &&
|
||||
match(Op0BO->getOperand(1),
|
||||
m_And(m_Shr(m_Value(V1), m_Value(V2)),
|
||||
m_ConstantInt(CC))) && V2 == Op1 &&
|
||||
match(Op0BO->getOperand(1), m_And(m_Shr(m_Value(V1), m_Value(V2)),
|
||||
m_ConstantInt(CC))) && V2 == Op1 &&
|
||||
cast<BinaryOperator>(Op0BO->getOperand(1))->getOperand(0)->hasOneUse()) {
|
||||
Instruction *YS = new ShiftInst(Instruction::Shl,
|
||||
Op0BO->getOperand(0), Op1,
|
||||
Op0BO->getName());
|
||||
Instruction *YS = BinaryOperator::create(Instruction::Shl,
|
||||
Op0BO->getOperand(0), Op1,
|
||||
Op0BO->getName());
|
||||
InsertNewInstBefore(YS, I); // (Y << C)
|
||||
Instruction *XM =
|
||||
BinaryOperator::createAnd(V1, ConstantExpr::getShl(CC, Op1),
|
||||
@ -5511,9 +5529,9 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
|
||||
match(Op0BO->getOperand(0),
|
||||
m_Shr(m_Value(V1), m_ConstantInt(CC))) && CC == Op1) {
|
||||
Instruction *YS = new ShiftInst(Instruction::Shl,
|
||||
Op0BO->getOperand(1), Op1,
|
||||
Op0BO->getName());
|
||||
Instruction *YS = BinaryOperator::create(Instruction::Shl,
|
||||
Op0BO->getOperand(1), Op1,
|
||||
Op0BO->getName());
|
||||
InsertNewInstBefore(YS, I); // (Y << C)
|
||||
Instruction *X =
|
||||
BinaryOperator::create(Op0BO->getOpcode(), V1, YS,
|
||||
@ -5531,9 +5549,9 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
m_ConstantInt(CC))) && V2 == Op1 &&
|
||||
cast<BinaryOperator>(Op0BO->getOperand(0))
|
||||
->getOperand(0)->hasOneUse()) {
|
||||
Instruction *YS = new ShiftInst(Instruction::Shl,
|
||||
Op0BO->getOperand(1), Op1,
|
||||
Op0BO->getName());
|
||||
Instruction *YS = BinaryOperator::create(Instruction::Shl,
|
||||
Op0BO->getOperand(1), Op1,
|
||||
Op0BO->getName());
|
||||
InsertNewInstBefore(YS, I); // (Y << C)
|
||||
Instruction *XM =
|
||||
BinaryOperator::createAnd(V1, ConstantExpr::getShl(CC, Op1),
|
||||
@ -5582,8 +5600,8 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
Constant *NewRHS = ConstantExpr::get(I.getOpcode(), Op0C, Op1);
|
||||
|
||||
Instruction *NewShift =
|
||||
new ShiftInst(I.getOpcode(), Op0BO->getOperand(0), Op1,
|
||||
Op0BO->getName());
|
||||
BinaryOperator::create(I.getOpcode(), Op0BO->getOperand(0), Op1,
|
||||
Op0BO->getName());
|
||||
Op0BO->setName("");
|
||||
InsertNewInstBefore(NewShift, I);
|
||||
|
||||
@ -5595,15 +5613,15 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
}
|
||||
|
||||
// Find out if this is a shift of a shift by a constant.
|
||||
ShiftInst *ShiftOp = 0;
|
||||
if (ShiftInst *Op0SI = dyn_cast<ShiftInst>(Op0))
|
||||
ShiftOp = Op0SI;
|
||||
else if (BitCastInst *CI = dyn_cast<BitCastInst>(Op0)) {
|
||||
// If this is a noop-integer cast of a shift instruction, use the shift.
|
||||
if (isa<ShiftInst>(CI->getOperand(0))) {
|
||||
ShiftOp = cast<ShiftInst>(CI->getOperand(0));
|
||||
}
|
||||
}
|
||||
BinaryOperator *ShiftOp = dyn_cast<BinaryOperator>(Op0);
|
||||
if (ShiftOp && !ShiftOp->isShift())
|
||||
ShiftOp = 0;
|
||||
if (!ShiftOp)
|
||||
if (BitCastInst *CI = dyn_cast<BitCastInst>(Op0))
|
||||
// If this is a noop-integer cast of a shift instruction, use the shift.
|
||||
if (BinaryOperator *SI = dyn_cast<BinaryOperator>(CI->getOperand(0)))
|
||||
if (SI->isShift())
|
||||
ShiftOp = SI;
|
||||
|
||||
if (ShiftOp && isa<ConstantInt>(ShiftOp->getOperand(1))) {
|
||||
// Find the operands and properties of the input shift. Note that the
|
||||
@ -5631,8 +5649,9 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
Amt = Op0->getType()->getPrimitiveSizeInBits();
|
||||
|
||||
Value *Op = ShiftOp->getOperand(0);
|
||||
ShiftInst *ShiftResult = new ShiftInst(I.getOpcode(), Op,
|
||||
ConstantInt::get(Type::Int8Ty, Amt));
|
||||
BinaryOperator *ShiftResult =
|
||||
BinaryOperator::create(I.getOpcode(), Op,
|
||||
ConstantInt::get(Op->getType(), Amt));
|
||||
if (I.getType() == ShiftResult->getType())
|
||||
return ShiftResult;
|
||||
InsertNewInstBefore(ShiftResult, I);
|
||||
@ -5660,21 +5679,25 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
if (ShiftAmt1 == ShiftAmt2) {
|
||||
return ReplaceInstUsesWith(I, Mask); // (A << c) >> c === A & c2
|
||||
} else if (ShiftAmt1 < ShiftAmt2) {
|
||||
return new ShiftInst(I.getOpcode(), Mask,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt2-ShiftAmt1));
|
||||
return BinaryOperator::create(I.getOpcode(), Mask,
|
||||
ConstantInt::get(Mask->getType(),
|
||||
ShiftAmt2-ShiftAmt1));
|
||||
} else if (isShiftOfUnsignedShift || isShiftOfLeftShift) {
|
||||
if (isShiftOfUnsignedShift && !isShiftOfLeftShift && isSignedShift) {
|
||||
return new ShiftInst(Instruction::LShr, Mask,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt1-ShiftAmt2));
|
||||
return BinaryOperator::create(Instruction::LShr, Mask,
|
||||
ConstantInt::get(Mask->getType(),
|
||||
ShiftAmt1-ShiftAmt2));
|
||||
} else {
|
||||
return new ShiftInst(ShiftOp->getOpcode(), Mask,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt1-ShiftAmt2));
|
||||
return BinaryOperator::create(ShiftOp->getOpcode(), Mask,
|
||||
ConstantInt::get(Mask->getType(),
|
||||
ShiftAmt1-ShiftAmt2));
|
||||
}
|
||||
} else {
|
||||
// (X >>s C1) << C2 where C1 > C2 === (X >>s (C1-C2)) & mask
|
||||
Instruction *Shift =
|
||||
new ShiftInst(ShiftOp->getOpcode(), Mask,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt1-ShiftAmt2));
|
||||
BinaryOperator::create(ShiftOp->getOpcode(), Mask,
|
||||
ConstantInt::get(Mask->getType(),
|
||||
ShiftAmt1-ShiftAmt2));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
C = ConstantInt::getAllOnesValue(Shift->getType());
|
||||
@ -5928,8 +5951,8 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty,
|
||||
case Instruction::LShr:
|
||||
case Instruction::Shl: {
|
||||
Value *LHS = EvaluateInDifferentType(I->getOperand(0), Ty, isSigned);
|
||||
Res = new ShiftInst((Instruction::OtherOps)I->getOpcode(), LHS,
|
||||
I->getOperand(1), I->getName());
|
||||
Res = BinaryOperator::create(Instruction::BinaryOps(I->getOpcode()), LHS,
|
||||
I->getOperand(1), I->getName());
|
||||
break;
|
||||
}
|
||||
case Instruction::Trunc:
|
||||
@ -6167,7 +6190,8 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
Instruction::CastOps opcode = (DestBitSize == SrcBitSize ?
|
||||
Instruction::BitCast : Instruction::Trunc);
|
||||
Value *Op0c = InsertOperandCastBefore(opcode, Op0, DestTy, SrcI);
|
||||
return new ShiftInst(Instruction::Shl, Op0c, Op1);
|
||||
Value *Op1c = InsertOperandCastBefore(opcode, Op1, DestTy, SrcI);
|
||||
return BinaryOperator::create(Instruction::Shl, Op0c, Op1c);
|
||||
}
|
||||
break;
|
||||
case Instruction::AShr:
|
||||
@ -6179,7 +6203,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
unsigned ShiftAmt = cast<ConstantInt>(Op1)->getZExtValue();
|
||||
if (SrcBitSize > ShiftAmt && SrcBitSize-ShiftAmt >= DestBitSize) {
|
||||
// Insert the new logical shift right.
|
||||
return new ShiftInst(Instruction::LShr, Op0, Op1);
|
||||
return BinaryOperator::create(Instruction::LShr, Op0, Op1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -6225,9 +6249,9 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
// Perform a logical shr by shiftamt.
|
||||
// Insert the shift to put the result in the low bit.
|
||||
In = InsertNewInstBefore(
|
||||
new ShiftInst(Instruction::LShr, In,
|
||||
ConstantInt::get(Type::Int8Ty, ShiftAmt),
|
||||
In->getName()+".lobit"), CI);
|
||||
BinaryOperator::create(Instruction::LShr, In,
|
||||
ConstantInt::get(In->getType(), ShiftAmt),
|
||||
In->getName()+".lobit"), CI);
|
||||
}
|
||||
|
||||
if ((Op1CV != 0) == isNE) { // Toggle the low bit.
|
||||
@ -6274,8 +6298,10 @@ Instruction *InstCombiner::visitTrunc(CastInst &CI) {
|
||||
|
||||
// Okay, we can shrink this. Truncate the input, then return a new
|
||||
// shift.
|
||||
Value *V = InsertCastBefore(Instruction::Trunc, SrcIOp0, Ty, CI);
|
||||
return new ShiftInst(Instruction::LShr, V, SrcI->getOperand(1));
|
||||
Value *V1 = InsertCastBefore(Instruction::Trunc, SrcIOp0, Ty, CI);
|
||||
Value *V2 = InsertCastBefore(Instruction::Trunc, SrcI->getOperand(1),
|
||||
Ty, CI);
|
||||
return BinaryOperator::create(Instruction::LShr, V1, V2);
|
||||
}
|
||||
} else { // This is a variable shr.
|
||||
|
||||
@ -6285,9 +6311,9 @@ Instruction *InstCombiner::visitTrunc(CastInst &CI) {
|
||||
if (CI.getType() == Type::Int1Ty && SrcI->hasOneUse()) {
|
||||
Value *One = ConstantInt::get(SrcI->getType(), 1);
|
||||
|
||||
Value *V = InsertNewInstBefore(new ShiftInst(Instruction::Shl, One,
|
||||
SrcI->getOperand(1),
|
||||
"tmp"), CI);
|
||||
Value *V = InsertNewInstBefore(
|
||||
BinaryOperator::create(Instruction::Shl, One, SrcI->getOperand(1),
|
||||
"tmp"), CI);
|
||||
V = InsertNewInstBefore(BinaryOperator::createAnd(V,
|
||||
SrcI->getOperand(0),
|
||||
"tmp"), CI);
|
||||
@ -6491,11 +6517,10 @@ static Constant *GetSelectFoldableConstant(Instruction *I) {
|
||||
case Instruction::Sub:
|
||||
case Instruction::Or:
|
||||
case Instruction::Xor:
|
||||
return Constant::getNullValue(I->getType());
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
return Constant::getNullValue(Type::Int8Ty);
|
||||
return Constant::getNullValue(I->getType());
|
||||
case Instruction::And:
|
||||
return ConstantInt::getAllOnesValue(I->getType());
|
||||
case Instruction::Mul:
|
||||
@ -6525,8 +6550,8 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI,
|
||||
TI->getType());
|
||||
}
|
||||
|
||||
// Only handle binary, compare and shift operators here.
|
||||
if (!isa<ShiftInst>(TI) && !isa<BinaryOperator>(TI))
|
||||
// Only handle binary operators here.
|
||||
if (!isa<BinaryOperator>(TI))
|
||||
return 0;
|
||||
|
||||
// Figure out if the operations have any operands in common.
|
||||
@ -6570,11 +6595,13 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI,
|
||||
return BinaryOperator::create(BO->getOpcode(), NewSI, MatchOp);
|
||||
}
|
||||
|
||||
assert(isa<ShiftInst>(TI) && "Should only have Shift here");
|
||||
assert(TI->isShift() && "Should only have Shift here");
|
||||
if (MatchIsOpZero)
|
||||
return new ShiftInst(cast<ShiftInst>(TI)->getOpcode(), MatchOp, NewSI);
|
||||
return BinaryOperator::create(Instruction::BinaryOps(TI->getOpcode()),
|
||||
MatchOp, NewSI);
|
||||
else
|
||||
return new ShiftInst(cast<ShiftInst>(TI)->getOpcode(), NewSI, MatchOp);
|
||||
return BinaryOperator::create(Instruction::BinaryOps(TI->getOpcode()),
|
||||
NewSI, MatchOp);
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
@ -6663,9 +6690,9 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
// same width. Make an all-ones value by inserting a AShr.
|
||||
Value *X = IC->getOperand(0);
|
||||
unsigned Bits = X->getType()->getPrimitiveSizeInBits();
|
||||
Constant *ShAmt = ConstantInt::get(Type::Int8Ty, Bits-1);
|
||||
Instruction *SRA = new ShiftInst(Instruction::AShr, X,
|
||||
ShAmt, "ones");
|
||||
Constant *ShAmt = ConstantInt::get(X->getType(), Bits-1);
|
||||
Instruction *SRA = BinaryOperator::create(Instruction::AShr, X,
|
||||
ShAmt, "ones");
|
||||
InsertNewInstBefore(SRA, SI);
|
||||
|
||||
// Finally, convert to the type of the select RHS. We figure out
|
||||
@ -6829,8 +6856,6 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
InsertNewInstBefore(NewSel, SI);
|
||||
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI))
|
||||
return BinaryOperator::create(BO->getOpcode(), FalseVal, NewSel);
|
||||
else if (ShiftInst *SI = dyn_cast<ShiftInst>(TVI))
|
||||
return new ShiftInst(SI->getOpcode(), FalseVal, NewSel);
|
||||
else {
|
||||
assert(0 && "Unknown instruction!!");
|
||||
}
|
||||
@ -6850,18 +6875,16 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
|
||||
if (OpToFold) {
|
||||
Constant *C = GetSelectFoldableConstant(FVI);
|
||||
std::string Name = FVI->getName(); FVI->setName("");
|
||||
std::string Name = FVI->getName();
|
||||
FVI->setName("");
|
||||
Instruction *NewSel =
|
||||
new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold),
|
||||
Name);
|
||||
InsertNewInstBefore(NewSel, SI);
|
||||
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI))
|
||||
return BinaryOperator::create(BO->getOpcode(), TrueVal, NewSel);
|
||||
else if (ShiftInst *SI = dyn_cast<ShiftInst>(FVI))
|
||||
return new ShiftInst(SI->getOpcode(), TrueVal, NewSel);
|
||||
else {
|
||||
else
|
||||
assert(0 && "Unknown instruction!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7377,8 +7400,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
||||
/// and a single binop.
|
||||
Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
|
||||
Instruction *FirstInst = cast<Instruction>(PN.getIncomingValue(0));
|
||||
assert(isa<BinaryOperator>(FirstInst) || isa<ShiftInst>(FirstInst) ||
|
||||
isa<GetElementPtrInst>(FirstInst) || isa<CmpInst>(FirstInst));
|
||||
assert(isa<BinaryOperator>(FirstInst) || isa<GetElementPtrInst>(FirstInst) ||
|
||||
isa<CmpInst>(FirstInst));
|
||||
unsigned Opc = FirstInst->getOpcode();
|
||||
Value *LHSVal = FirstInst->getOperand(0);
|
||||
Value *RHSVal = FirstInst->getOperand(1);
|
||||
@ -7452,8 +7475,6 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
|
||||
else if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst))
|
||||
return CmpInst::create(CIOp->getOpcode(), CIOp->getPredicate(), LHSVal,
|
||||
RHSVal);
|
||||
else if (ShiftInst *SI = dyn_cast<ShiftInst>(FirstInst))
|
||||
return new ShiftInst(SI->getOpcode(), LHSVal, RHSVal);
|
||||
else {
|
||||
assert(isa<GetElementPtrInst>(FirstInst));
|
||||
return new GetElementPtrInst(LHSVal, RHSVal);
|
||||
@ -7513,8 +7534,7 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) {
|
||||
bool isVolatile = false;
|
||||
if (isa<CastInst>(FirstInst)) {
|
||||
CastSrcTy = FirstInst->getOperand(0)->getType();
|
||||
} else if (isa<BinaryOperator>(FirstInst) || isa<ShiftInst>(FirstInst) ||
|
||||
isa<CmpInst>(FirstInst)) {
|
||||
} else if (isa<BinaryOperator>(FirstInst) || isa<CmpInst>(FirstInst)) {
|
||||
// Can fold binop, compare or shift here if the RHS is a constant,
|
||||
// otherwise call FoldPHIArgBinOpIntoPHI.
|
||||
ConstantOp = dyn_cast<Constant>(FirstInst->getOperand(1));
|
||||
@ -7596,8 +7616,7 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) {
|
||||
return CmpInst::create(CIOp->getOpcode(), CIOp->getPredicate(),
|
||||
PhiVal, ConstantOp);
|
||||
else
|
||||
return new ShiftInst(cast<ShiftInst>(FirstInst)->getOpcode(),
|
||||
PhiVal, ConstantOp);
|
||||
assert(0 && "Unknown operation");
|
||||
}
|
||||
|
||||
/// DeadPHICycle - Return true if this PHI node is only used by a PHI node cycle
|
||||
|
@ -384,7 +384,7 @@ bool LICM::canSinkOrHoistInst(Instruction &I) {
|
||||
}
|
||||
|
||||
// Otherwise these instructions are hoistable/sinkable
|
||||
return isa<BinaryOperator>(I) || isa<ShiftInst>(I) || isa<CastInst>(I) ||
|
||||
return isa<BinaryOperator>(I) || isa<CastInst>(I) ||
|
||||
isa<SelectInst>(I) || isa<GetElementPtrInst>(I) || isa<CmpInst>(I);
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,6 @@ private:
|
||||
void visitSelectInst(SelectInst &I);
|
||||
void visitBinaryOperator(Instruction &I);
|
||||
void visitCmpInst(CmpInst &I);
|
||||
void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
|
||||
void visitExtractElementInst(ExtractElementInst &I);
|
||||
void visitInsertElementInst(InsertElementInst &I);
|
||||
void visitShuffleVectorInst(ShuffleVectorInst &I);
|
||||
|
@ -655,9 +655,9 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) {
|
||||
} else {
|
||||
assert(NV->getType()->isInteger() && "Unknown promotion!");
|
||||
if (Offset && Offset < TD.getTypeSize(NV->getType())*8) {
|
||||
NV = new ShiftInst(Instruction::LShr, NV,
|
||||
ConstantInt::get(Type::Int8Ty, Offset),
|
||||
LI->getName(), LI);
|
||||
NV = BinaryOperator::create(Instruction::LShr, NV,
|
||||
ConstantInt::get(NV->getType(), Offset),
|
||||
LI->getName(), LI);
|
||||
}
|
||||
|
||||
// If the result is an integer, this is a trunc or bitcast.
|
||||
@ -740,9 +740,9 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) {
|
||||
SV = CastInst::createZExtOrBitCast(SV, AllocaType,
|
||||
SV->getName(), SI);
|
||||
if (Offset && Offset < AllocaType->getPrimitiveSizeInBits())
|
||||
SV = new ShiftInst(Instruction::Shl, SV,
|
||||
ConstantInt::get(Type::Int8Ty, Offset),
|
||||
SV->getName()+".adj", SI);
|
||||
SV = BinaryOperator::create(Instruction::Shl, SV,
|
||||
ConstantInt::get(SV->getType(), Offset),
|
||||
SV->getName()+".adj", SI);
|
||||
// Mask out the bits we are about to insert from the old value.
|
||||
unsigned TotalBits = TD.getTypeSize(SV->getType())*8;
|
||||
if (TotalBits != SrcSize) {
|
||||
|
@ -1272,8 +1272,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
|
||||
|
||||
// Shift Left & Right print both types even for Ubyte LHS, and select prints
|
||||
// types even if all operands are bools.
|
||||
if (isa<ShiftInst>(I) || isa<SelectInst>(I) || isa<StoreInst>(I) ||
|
||||
isa<ShuffleVectorInst>(I)) {
|
||||
if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)) {
|
||||
PrintAllTypes = true;
|
||||
} else {
|
||||
for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
|
||||
|
@ -1302,10 +1302,7 @@ namespace llvm {
|
||||
if (Instruction::isCast(V.opcode))
|
||||
return new UnaryConstantExpr(V.opcode, V.operands[0], Ty);
|
||||
if ((V.opcode >= Instruction::BinaryOpsBegin &&
|
||||
V.opcode < Instruction::BinaryOpsEnd) ||
|
||||
V.opcode == Instruction::Shl ||
|
||||
V.opcode == Instruction::LShr ||
|
||||
V.opcode == Instruction::AShr)
|
||||
V.opcode < Instruction::BinaryOpsEnd))
|
||||
return new BinaryConstantExpr(V.opcode, V.operands[0], V.operands[1]);
|
||||
if (V.opcode == Instruction::Select)
|
||||
return new SelectConstantExpr(V.operands[0], V.operands[1],
|
||||
@ -1362,12 +1359,6 @@ namespace llvm {
|
||||
OldC->getOperand(1),
|
||||
OldC->getOperand(2));
|
||||
break;
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(),
|
||||
OldC->getOperand(0), OldC->getOperand(1));
|
||||
break;
|
||||
default:
|
||||
assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin &&
|
||||
OldC->getOpcode() < Instruction::BinaryOpsEnd);
|
||||
@ -1603,10 +1594,6 @@ Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) {
|
||||
|
||||
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
|
||||
Constant *C1, Constant *C2) {
|
||||
if (Opcode == Instruction::Shl || Opcode == Instruction::LShr ||
|
||||
Opcode == Instruction::AShr)
|
||||
return getShiftTy(ReqTy, Opcode, C1, C2);
|
||||
|
||||
// Check the operands for consistency first
|
||||
assert(Opcode >= Instruction::BinaryOpsBegin &&
|
||||
Opcode < Instruction::BinaryOpsEnd &&
|
||||
@ -1689,7 +1676,7 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
assert(C2->getType() == Type::Int8Ty && "Shift should be by i8!");
|
||||
assert(C1->getType() == C2->getType() && "Op types should be identical!");
|
||||
assert(C1->getType()->isInteger() &&
|
||||
"Tried to create a shift operation on a non-integer type!");
|
||||
break;
|
||||
@ -1724,26 +1711,6 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
|
||||
return ExprConstants->getOrCreate(ReqTy, Key);
|
||||
}
|
||||
|
||||
/// getShiftTy - Return a shift left or shift right constant expr
|
||||
Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode,
|
||||
Constant *C1, Constant *C2) {
|
||||
// Check the operands for consistency first
|
||||
assert((Opcode == Instruction::Shl ||
|
||||
Opcode == Instruction::LShr ||
|
||||
Opcode == Instruction::AShr) &&
|
||||
"Invalid opcode in binary constant expression");
|
||||
assert(C1->getType()->isInteger() && C2->getType() == Type::Int8Ty &&
|
||||
"Invalid operand types for Shift constant expr!");
|
||||
|
||||
if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
|
||||
return FC; // Fold a few common cases...
|
||||
|
||||
// Look up the constant in the table first to ensure uniqueness
|
||||
std::vector<Constant*> argVec(1, C1); argVec.push_back(C2);
|
||||
ExprMapKeyType Key(Opcode, argVec);
|
||||
return ExprConstants->getOrCreate(ReqTy, Key);
|
||||
}
|
||||
|
||||
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
|
||||
Value* const *Idxs,
|
||||
unsigned NumIdx) {
|
||||
|
@ -1088,6 +1088,14 @@ void BinaryOperator::init(BinaryOps iType)
|
||||
cast<PackedType>(getType())->getElementType()->isFloatingPoint()))
|
||||
&& "Incorrect operand type (not floating point) for FREM");
|
||||
break;
|
||||
case Shl:
|
||||
case LShr:
|
||||
case AShr:
|
||||
assert(getType() == LHS->getType() &&
|
||||
"Shift operation should return same type as operands!");
|
||||
assert(getType()->isInteger() &&
|
||||
"Shift operation requires integer operands");
|
||||
break;
|
||||
case And: case Or:
|
||||
case Xor:
|
||||
assert(getType() == LHS->getType() &&
|
||||
@ -2299,7 +2307,6 @@ CastInst *PtrToIntInst::clone() const { return new PtrToIntInst(*this); }
|
||||
CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); }
|
||||
CastInst *BitCastInst::clone() const { return new BitCastInst(*this); }
|
||||
CallInst *CallInst::clone() const { return new CallInst(*this); }
|
||||
ShiftInst *ShiftInst::clone() const { return new ShiftInst(*this); }
|
||||
SelectInst *SelectInst::clone() const { return new SelectInst(*this); }
|
||||
VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
|
||||
|
||||
|
@ -196,7 +196,6 @@ namespace { // Anonymous namespace for class
|
||||
void visitBinaryOperator(BinaryOperator &B);
|
||||
void visitICmpInst(ICmpInst &IC);
|
||||
void visitFCmpInst(FCmpInst &FC);
|
||||
void visitShiftInst(ShiftInst &SI);
|
||||
void visitExtractElementInst(ExtractElementInst &EI);
|
||||
void visitInsertElementInst(InsertElementInst &EI);
|
||||
void visitShuffleVectorInst(ShuffleVectorInst &EI);
|
||||
@ -713,9 +712,11 @@ void Verifier::visitBinaryOperator(BinaryOperator &B) {
|
||||
Assert1(B.getOperand(0)->getType() == B.getOperand(1)->getType(),
|
||||
"Both operands to a binary operator are not of the same type!", &B);
|
||||
|
||||
switch (B.getOpcode()) {
|
||||
// Check that logical operators are only used with integral operands.
|
||||
if (B.getOpcode() == Instruction::And || B.getOpcode() == Instruction::Or ||
|
||||
B.getOpcode() == Instruction::Xor) {
|
||||
case Instruction::And:
|
||||
case Instruction::Or:
|
||||
case Instruction::Xor:
|
||||
Assert1(B.getType()->isInteger() ||
|
||||
(isa<PackedType>(B.getType()) &&
|
||||
cast<PackedType>(B.getType())->getElementType()->isInteger()),
|
||||
@ -723,7 +724,16 @@ void Verifier::visitBinaryOperator(BinaryOperator &B) {
|
||||
Assert1(B.getType() == B.getOperand(0)->getType(),
|
||||
"Logical operators must have same type for operands and result!",
|
||||
&B);
|
||||
} else {
|
||||
break;
|
||||
case Instruction::Shl:
|
||||
case Instruction::LShr:
|
||||
case Instruction::AShr:
|
||||
Assert1(B.getType()->isInteger(),
|
||||
"Shift must return an integer result!", &B);
|
||||
Assert1(B.getType() == B.getOperand(0)->getType(),
|
||||
"Shift return type must be same as operands!", &B);
|
||||
/* FALL THROUGH */
|
||||
default:
|
||||
// Arithmetic operators only work on integer or fp values
|
||||
Assert1(B.getType() == B.getOperand(0)->getType(),
|
||||
"Arithmetic operators must have same type for operands and result!",
|
||||
@ -731,6 +741,7 @@ void Verifier::visitBinaryOperator(BinaryOperator &B) {
|
||||
Assert1(B.getType()->isInteger() || B.getType()->isFloatingPoint() ||
|
||||
isa<PackedType>(B.getType()),
|
||||
"Arithmetic operators must have integer, fp, or packed type!", &B);
|
||||
break;
|
||||
}
|
||||
|
||||
visitInstruction(B);
|
||||
@ -760,16 +771,6 @@ void Verifier::visitFCmpInst(FCmpInst& FC) {
|
||||
visitInstruction(FC);
|
||||
}
|
||||
|
||||
void Verifier::visitShiftInst(ShiftInst &SI) {
|
||||
Assert1(SI.getType()->isInteger(),
|
||||
"Shift must return an integer result!", &SI);
|
||||
Assert1(SI.getType() == SI.getOperand(0)->getType(),
|
||||
"Shift return type must be same as first operand!", &SI);
|
||||
Assert1(SI.getOperand(1)->getType() == Type::Int8Ty,
|
||||
"Second operand to shift must be ubyte type!", &SI);
|
||||
visitInstruction(SI);
|
||||
}
|
||||
|
||||
void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
|
||||
Assert1(ExtractElementInst::isValidOperands(EI.getOperand(0),
|
||||
EI.getOperand(1)),
|
||||
|
@ -1,4 +1,4 @@
|
||||
; Found by inspection of the code
|
||||
; RUN: llvm-as 2>&1 < %s > /dev/null | grep "Shift constant expression"
|
||||
; RUN: llvm-as 2>&1 < %s > /dev/null | grep "Logical operator requires integral"
|
||||
|
||||
global i32 ashr (float 1.0, i8 2)
|
||||
global i32 ashr (float 1.0, float 2.0)
|
||||
|
18
test/Assembler/2007-02-01-UpgradeShift.ll
Normal file
18
test/Assembler/2007-02-01-UpgradeShift.ll
Normal file
@ -0,0 +1,18 @@
|
||||
; Test that upgrading shift instructions and constant expressions works
|
||||
; correctly.
|
||||
; RUN: llvm-upgrade < %s | grep 'ashr i32 .X, 2' &&
|
||||
; RUN: llvm-upgrade < %s | grep 'lshr i32 .X, 2' &&
|
||||
; RUN: llvm-upgrade < %s | grep 'shl i32 .X, 2' &&
|
||||
; RUN: llvm-upgrade < %s | grep 'ashr i32 .X, 6' &&
|
||||
; RUN: llvm-upgrade < %s | grep 'lshr i32 .X, 1' &&
|
||||
; RUN: llvm-upgrade < %s | grep 'shl i32 .X, 1'
|
||||
|
||||
void %test(int %X) {
|
||||
%A = ashr int %X, ubyte 2
|
||||
%B = lshr int %X, ubyte 2
|
||||
%C = shl int %X, ubyte 2
|
||||
%D = ashr int %X, ubyte trunc ( int shl (int 3, ubyte 1) to ubyte )
|
||||
%E = lshr int %X, ubyte trunc ( int ashr (int 3, ubyte 1) to ubyte )
|
||||
%F = shl int %X, ubyte trunc ( int lshr (int 3, ubyte 1) to ubyte )
|
||||
ret void
|
||||
}
|
@ -19,13 +19,13 @@ cond_next489: ; preds = %cond_false, %bb471
|
||||
%tmp502 = load i32* null ; <i32> [#uses=1]
|
||||
%tmp542 = getelementptr [6 x [4 x [4 x i32]]]* @quant_coef, i32 0, i32 0, i32 %i.8, i32 %j.7 ; <i32*> [#uses=1]
|
||||
%tmp543 = load i32* %tmp542 ; <i32> [#uses=1]
|
||||
%tmp548 = ashr i32 0, i8 0 ; <i32> [#uses=3]
|
||||
%tmp548 = ashr i32 0, 0 ; <i32> [#uses=3]
|
||||
%tmp561 = sub i32 0, %tmp496 ; <i32> [#uses=3]
|
||||
%abscond563 = icmp sgt i32 %tmp561, -1 ; <i1> [#uses=1]
|
||||
%abs564 = select i1 %abscond563, i32 %tmp561, i32 0 ; <i32> [#uses=1]
|
||||
%tmp572 = mul i32 %abs564, %tmp543 ; <i32> [#uses=1]
|
||||
%tmp574 = add i32 %tmp572, 0 ; <i32> [#uses=1]
|
||||
%tmp576 = ashr i32 %tmp574, i8 0 ; <i32> [#uses=7]
|
||||
%tmp576 = ashr i32 %tmp574, 0 ; <i32> [#uses=7]
|
||||
%tmp579 = icmp eq i32 %tmp548, %tmp576 ; <i1> [#uses=1]
|
||||
br i1 %tmp579, label %bb712, label %cond_next589
|
||||
|
||||
@ -40,8 +40,8 @@ cond_next589: ; preds = %cond_next489
|
||||
%tmp642 = call fastcc i32 @sign( i32 %tmp576, i32 %tmp561 ) ; <i32> [#uses=1]
|
||||
%tmp650 = mul i32 %tmp606, %tmp642 ; <i32> [#uses=1]
|
||||
%tmp656 = mul i32 %tmp650, %tmp612 ; <i32> [#uses=1]
|
||||
%tmp658 = shl i32 %tmp656, i8 0 ; <i32> [#uses=1]
|
||||
%tmp659 = ashr i32 %tmp658, i8 6 ; <i32> [#uses=1]
|
||||
%tmp658 = shl i32 %tmp656, 0 ; <i32> [#uses=1]
|
||||
%tmp659 = ashr i32 %tmp658, 6 ; <i32> [#uses=1]
|
||||
%tmp660 = sub i32 0, %tmp659 ; <i32> [#uses=1]
|
||||
%tmp666 = sub i32 %tmp660, %tmp496 ; <i32> [#uses=1]
|
||||
%tmp667 = sitofp i32 %tmp666 to double ; <double> [#uses=2]
|
||||
@ -85,8 +85,8 @@ cond_true740: ; preds = %bb737
|
||||
%tmp786 = load i32* %tmp785 ; <i32> [#uses=1]
|
||||
%tmp781 = mul i32 %tmp780, %tmp761 ; <i32> [#uses=1]
|
||||
%tmp787 = mul i32 %tmp781, %tmp786 ; <i32> [#uses=1]
|
||||
%tmp789 = shl i32 %tmp787, i8 0 ; <i32> [#uses=1]
|
||||
%tmp790 = ashr i32 %tmp789, i8 6 ; <i32> [#uses=1]
|
||||
%tmp789 = shl i32 %tmp787, 0 ; <i32> [#uses=1]
|
||||
%tmp790 = ashr i32 %tmp789, 6 ; <i32> [#uses=1]
|
||||
br label %cond_next791
|
||||
|
||||
cond_next791: ; preds = %cond_true740, %bb737
|
||||
|
@ -7,7 +7,7 @@ define void @f1() {
|
||||
%D = alloca %struct.rtx_def, align 1
|
||||
%tmp1 = bitcast %struct.rtx_def* %D to i32*
|
||||
%tmp7 = load i32* %tmp1
|
||||
%tmp14 = lshr i32 %tmp7, i8 1
|
||||
%tmp14 = lshr i32 %tmp7, 1
|
||||
%tmp1415 = and i32 %tmp14, 1
|
||||
call void (i32, ...)* @printf( i32 undef, i32 0, i32 %tmp1415 )
|
||||
ret void
|
||||
|
@ -1,36 +1,36 @@
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep and | wc -l | grep 1 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep orr | wc -l | grep 1 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep eor | wc -l | grep 1 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep mov.*lsl | wc -l | grep 1 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep mov.*asr | wc -l | grep 1
|
||||
; RUN: llvm-as < %s | llc -march=arm &&
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep and | wc -l | grep 1 &&
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep orr | wc -l | grep 1 &&
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep eor | wc -l | grep 1 &&
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep mov.*lsl | wc -l | grep 1 &&
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep mov.*asr | wc -l | grep 1
|
||||
|
||||
int %f1(int %a, int %b) {
|
||||
define i32 @f1(i32 %a, i32 %b) {
|
||||
entry:
|
||||
%tmp2 = and int %b, %a ; <int> [#uses=1]
|
||||
ret int %tmp2
|
||||
%tmp2 = and i32 %b, %a ; <i32> [#uses=1]
|
||||
ret i32 %tmp2
|
||||
}
|
||||
|
||||
int %f2(int %a, int %b) {
|
||||
define i32 @f2(i32 %a, i32 %b) {
|
||||
entry:
|
||||
%tmp2 = or int %b, %a ; <int> [#uses=1]
|
||||
ret int %tmp2
|
||||
%tmp2 = or i32 %b, %a ; <i32> [#uses=1]
|
||||
ret i32 %tmp2
|
||||
}
|
||||
|
||||
int %f3(int %a, int %b) {
|
||||
define i32 @f3(i32 %a, i32 %b) {
|
||||
entry:
|
||||
%tmp2 = xor int %b, %a ; <int> [#uses=1]
|
||||
ret int %tmp2
|
||||
%tmp2 = xor i32 %b, %a ; <i32> [#uses=1]
|
||||
ret i32 %tmp2
|
||||
}
|
||||
|
||||
int %f4(int %a, ubyte %b) {
|
||||
define i32 @f4(i32 %a, i32 %b) {
|
||||
entry:
|
||||
%tmp3 = shl int %a, ubyte %b ; <int> [#uses=1]
|
||||
ret int %tmp3
|
||||
%tmp3 = shl i32 %a, %b ; <i32> [#uses=1]
|
||||
ret i32 %tmp3
|
||||
}
|
||||
|
||||
int %f5(int %a, ubyte %b) {
|
||||
define i32 @f5(i32 %a, i32 %b) {
|
||||
entry:
|
||||
%tmp3 = shr int %a, ubyte %b ; <int> [#uses=1]
|
||||
ret int %tmp3
|
||||
%tmp3 = ashr i32 %a, %b ; <i32> [#uses=1]
|
||||
ret i32 %tmp3
|
||||
}
|
||||
|
@ -5,27 +5,27 @@
|
||||
; RUN: llvm-as < %s | llc -march=arm | grep __lshrdi3 &&
|
||||
; RUN: llvm-as < %s | llc -march=arm -enable-thumb
|
||||
|
||||
define i64 @f00(i64 %A, i64 %B) {
|
||||
define i64 @f0(i64 %A, i64 %B) {
|
||||
%tmp = bitcast i64 %A to i64
|
||||
%tmp2 = lshr i64 %B, i8 1
|
||||
%tmp2 = lshr i64 %B, 1
|
||||
%tmp3 = sub i64 %tmp, %tmp2
|
||||
ret i64 %tmp3
|
||||
}
|
||||
|
||||
define i32 @f1(i64 %x, i8 %y) {
|
||||
%a = shl i64 %x, i8 %y
|
||||
define i32 @f1(i64 %x, i64 %y) {
|
||||
%a = shl i64 %x, %y
|
||||
%b = trunc i64 %a to i32
|
||||
ret i32 %b
|
||||
}
|
||||
|
||||
define i32 @f2(i64 %x, i8 %y) {
|
||||
%a = ashr i64 %x, i8 %y
|
||||
define i32 @f2(i64 %x, i64 %y) {
|
||||
%a = ashr i64 %x, %y
|
||||
%b = trunc i64 %a to i32
|
||||
ret i32 %b
|
||||
}
|
||||
|
||||
define i32 @f3(i64 %x, i8 %y) {
|
||||
%a = lshr i64 %x, i8 %y
|
||||
define i32 @f3(i64 %x, i64 %y) {
|
||||
%a = lshr i64 %x, %y
|
||||
%b = trunc i64 %a to i32
|
||||
ret i32 %b
|
||||
}
|
||||
|
@ -4,16 +4,16 @@
|
||||
; RUN: llvm-as < %s | llc -march=arm -mattr=+v6 | grep "sxtab" | wc -l | grep 1
|
||||
|
||||
define i8 @test1(i32 %A) sext {
|
||||
%B = lshr i32 %A, i8 8
|
||||
%C = shl i32 %A, i8 24
|
||||
%B = lshr i32 %A, 8
|
||||
%C = shl i32 %A, 24
|
||||
%D = or i32 %B, %C
|
||||
%E = trunc i32 %D to i8
|
||||
ret i8 %E
|
||||
}
|
||||
|
||||
define i32 @test2(i32 %A, i32 %X) sext {
|
||||
%B = lshr i32 %A, i8 8
|
||||
%C = shl i32 %A, i8 24
|
||||
%B = lshr i32 %A, 8
|
||||
%C = shl i32 %A, 24
|
||||
%D = or i32 %B, %C
|
||||
%E = trunc i32 %D to i8
|
||||
%F = sext i8 %E to i32
|
||||
|
@ -17,8 +17,8 @@ define i32 @test2(i32 %A.u, i32 %B.u) zext {
|
||||
}
|
||||
|
||||
define i32 @test3(i32 %A.u) zext {
|
||||
%B.u = lshr i32 %A.u, i8 8
|
||||
%C.u = shl i32 %A.u, i8 24
|
||||
%B.u = lshr i32 %A.u, 8
|
||||
%C.u = shl i32 %A.u, 24
|
||||
%D.u = or i32 %B.u, %C.u
|
||||
%E.u = trunc i32 %D.u to i16
|
||||
%F.u = zext i16 %E.u to i32
|
||||
|
@ -69,112 +69,112 @@ entry:
|
||||
|
||||
define i32 @a4l(i32 sext %x.s, i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 2 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 2 ; <i32> [#uses=1]
|
||||
%tmp.3.s = add i32 %tmp.1.s, %x.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @a8l(i32 sext %x.s, i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 3 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 3 ; <i32> [#uses=1]
|
||||
%tmp.3.s = add i32 %tmp.1.s, %x.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @a4q(i64 %x.s, i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 2 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 2 ; <i64> [#uses=1]
|
||||
%tmp.3.s = add i64 %tmp.1.s, %x.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @a8q(i64 %x.s, i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 3 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 3 ; <i64> [#uses=1]
|
||||
%tmp.3.s = add i64 %tmp.1.s, %x.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @a4li(i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 2 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 2 ; <i32> [#uses=1]
|
||||
%tmp.3.s = add i32 100, %tmp.1.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @a8li(i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 3 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 3 ; <i32> [#uses=1]
|
||||
%tmp.3.s = add i32 100, %tmp.1.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @a4qi(i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 2 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 2 ; <i64> [#uses=1]
|
||||
%tmp.3.s = add i64 100, %tmp.1.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @a8qi(i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 3 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 3 ; <i64> [#uses=1]
|
||||
%tmp.3.s = add i64 100, %tmp.1.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @s4l(i32 sext %x.s, i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 2 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 2 ; <i32> [#uses=1]
|
||||
%tmp.3.s = sub i32 %tmp.1.s, %x.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @s8l(i32 sext %x.s, i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 3 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 3 ; <i32> [#uses=1]
|
||||
%tmp.3.s = sub i32 %tmp.1.s, %x.s ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @s4q(i64 %x.s, i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 2 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 2 ; <i64> [#uses=1]
|
||||
%tmp.3.s = sub i64 %tmp.1.s, %x.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @s8q(i64 %x.s, i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 3 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 3 ; <i64> [#uses=1]
|
||||
%tmp.3.s = sub i64 %tmp.1.s, %x.s ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @s4li(i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 2 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 2 ; <i32> [#uses=1]
|
||||
%tmp.3.s = sub i32 %tmp.1.s, 100 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i32 @s8li(i32 sext %y.s) sext {
|
||||
entry:
|
||||
%tmp.1.s = shl i32 %y.s, i8 3 ; <i32> [#uses=1]
|
||||
%tmp.1.s = shl i32 %y.s, 3 ; <i32> [#uses=1]
|
||||
%tmp.3.s = sub i32 %tmp.1.s, 100 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @s4qi(i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 2 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 2 ; <i64> [#uses=1]
|
||||
%tmp.3.s = sub i64 %tmp.1.s, 100 ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
||||
define i64 @s8qi(i64 %y.s) {
|
||||
entry:
|
||||
%tmp.1.s = shl i64 %y.s, i8 3 ; <i64> [#uses=1]
|
||||
%tmp.1.s = shl i64 %y.s, 3 ; <i64> [#uses=1]
|
||||
%tmp.3.s = sub i64 %tmp.1.s, 100 ; <i64> [#uses=1]
|
||||
ret i64 %tmp.3.s
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define void @test(i8* %P) {
|
||||
%W = load i8* %P
|
||||
%X = shl i8 %W, i8 1
|
||||
%X = shl i8 %W, 1
|
||||
%Y = add i8 %X, 2
|
||||
%Z = and i8 %Y, 254 ; dead and
|
||||
store i8 %Z, i8* %P
|
||||
@ -12,7 +12,7 @@ define void @test(i8* %P) {
|
||||
|
||||
define i16 @test2(i16 zext %crc) zext {
|
||||
; No and's should be needed for the i16s here.
|
||||
%tmp.1 = lshr i16 %crc, i8 1
|
||||
%tmp.1 = lshr i16 %crc, 1
|
||||
%tmp.7 = xor i16 %tmp.1, 40961
|
||||
ret i16 %tmp.7
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ define i16 @test2(i16 sext %X, i16 sext %x) sext {
|
||||
%tmp = sext i16 %X to i32
|
||||
%tmp1 = sext i16 %x to i32
|
||||
%tmp2 = add i32 %tmp, %tmp1
|
||||
%tmp4 = ashr i32 %tmp2, i8 1
|
||||
%tmp4 = ashr i32 %tmp2, 1
|
||||
%tmp5 = trunc i32 %tmp4 to i16
|
||||
%tmp45 = sext i16 %tmp5 to i32
|
||||
%retval = trunc i32 %tmp45 to i16
|
||||
@ -22,7 +22,7 @@ define i16 @test2(i16 sext %X, i16 sext %x) sext {
|
||||
}
|
||||
|
||||
define i16 @test3(i32 zext %X) sext {
|
||||
%tmp1 = lshr i32 %X, i8 16
|
||||
%tmp1 = lshr i32 %X, 16
|
||||
%tmp2 = trunc i32 %tmp1 to i16
|
||||
ret i16 %tmp2
|
||||
}
|
||||
|
@ -1,30 +1,27 @@
|
||||
; All of these ands and shifts should be folded into rlw[i]nm instructions
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | not grep and &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | not grep srawi &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | not grep srwi &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | not grep slwi &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | grep rlwnm | wc -l | grep 1 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | grep rlwinm | wc -l | grep 1
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | not grep and &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | not grep srawi &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | not grep srwi &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | not grep slwi &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | grep rlwnm | wc -l | grep 1 &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | grep rlwinm | wc -l | grep 1
|
||||
|
||||
|
||||
implementation ; Functions:
|
||||
|
||||
uint %test1(uint %X, int %Y) {
|
||||
define i32 @test1(i32 %X, i32 %Y) {
|
||||
entry:
|
||||
%tmp = cast int %Y to ubyte ; <ubyte> [#uses=2]
|
||||
%tmp1 = shl uint %X, ubyte %tmp ; <uint> [#uses=1]
|
||||
%tmp2 = sub ubyte 32, %tmp ; <ubyte> [#uses=1]
|
||||
%tmp3 = shr uint %X, ubyte %tmp2 ; <uint> [#uses=1]
|
||||
%tmp4 = or uint %tmp1, %tmp3 ; <uint> [#uses=1]
|
||||
%tmp6 = and uint %tmp4, 127 ; <uint> [#uses=1]
|
||||
ret uint %tmp6
|
||||
%tmp = trunc i32 %Y to i8 ; <i8> [#uses=2]
|
||||
%tmp1 = shl i32 %X, %Y ; <i32> [#uses=1]
|
||||
%tmp2 = sub i32 32, %Y ; <i8> [#uses=1]
|
||||
%tmp3 = lshr i32 %X, %tmp2 ; <i32> [#uses=1]
|
||||
%tmp4 = or i32 %tmp1, %tmp3 ; <i32> [#uses=1]
|
||||
%tmp6 = and i32 %tmp4, 127 ; <i32> [#uses=1]
|
||||
ret i32 %tmp6
|
||||
}
|
||||
|
||||
uint %test2(uint %X) {
|
||||
define i32 @test2(i32 %X) {
|
||||
entry:
|
||||
%tmp1 = shr uint %X, ubyte 27 ; <uint> [#uses=1]
|
||||
%tmp2 = shl uint %X, ubyte 5 ; <uint> [#uses=1]
|
||||
%tmp2.masked = and uint %tmp2, 96 ; <uint> [#uses=1]
|
||||
%tmp5 = or uint %tmp1, %tmp2.masked ; <uint> [#uses=1]
|
||||
ret uint %tmp5
|
||||
%tmp1 = lshr i32 %X, 27 ; <i32> [#uses=1]
|
||||
%tmp2 = shl i32 %X, 5 ; <i32> [#uses=1]
|
||||
%tmp2.masked = and i32 %tmp2, 96 ; <i32> [#uses=1]
|
||||
%tmp5 = or i32 %tmp1, %tmp2.masked ; <i32> [#uses=1]
|
||||
ret i32 %tmp5
|
||||
}
|
||||
|
@ -1,53 +1,38 @@
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | not grep or &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | \
|
||||
; RUN: grep rlwnm | wc -l | grep 2 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | \
|
||||
; RUN: grep rlwinm | wc -l | grep 2
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | not grep or &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | grep rlwnm | wc -l | grep 2 &&
|
||||
; RUN: llvm-as < %s | llc -march=ppc32 | grep rlwinm | wc -l | grep 2
|
||||
|
||||
implementation ; Functions:
|
||||
|
||||
int %rotlw(uint %x, int %sh) {
|
||||
define i32 @rotlw(i32 %x, i32 %sh) {
|
||||
entry:
|
||||
%tmp.3 = cast int %sh to ubyte ; <ubyte> [#uses=1]
|
||||
%x = cast uint %x to int ; <int> [#uses=1]
|
||||
%tmp.7 = sub int 32, %sh ; <int> [#uses=1]
|
||||
%tmp.9 = cast int %tmp.7 to ubyte ; <ubyte> [#uses=1]
|
||||
%tmp.10 = shr uint %x, ubyte %tmp.9 ; <uint> [#uses=1]
|
||||
%tmp.4 = shl int %x, ubyte %tmp.3 ; <int> [#uses=1]
|
||||
%tmp.10 = cast uint %tmp.10 to int ; <int> [#uses=1]
|
||||
%tmp.12 = or int %tmp.10, %tmp.4 ; <int> [#uses=1]
|
||||
ret int %tmp.12
|
||||
%tmp.7 = sub i32 32, %sh ; <i32> [#uses=1]
|
||||
%tmp.10 = lshr i32 %x, %tmp.7 ; <i32> [#uses=2]
|
||||
%tmp.4 = shl i32 %x, %sh ; <i32> [#uses=1]
|
||||
%tmp.12 = or i32 %tmp.10, %tmp.4 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.12
|
||||
}
|
||||
|
||||
int %rotrw(uint %x, int %sh) {
|
||||
define i32 @rotrw(i32 %x, i32 %sh) {
|
||||
entry:
|
||||
%tmp.3 = cast int %sh to ubyte ; <ubyte> [#uses=1]
|
||||
%tmp.4 = shr uint %x, ubyte %tmp.3 ; <uint> [#uses=1]
|
||||
%tmp.7 = sub int 32, %sh ; <int> [#uses=1]
|
||||
%tmp.9 = cast int %tmp.7 to ubyte ; <ubyte> [#uses=1]
|
||||
%x = cast uint %x to int ; <int> [#uses=1]
|
||||
%tmp.4 = cast uint %tmp.4 to int ; <int> [#uses=1]
|
||||
%tmp.10 = shl int %x, ubyte %tmp.9 ; <int> [#uses=1]
|
||||
%tmp.12 = or int %tmp.4, %tmp.10 ; <int> [#uses=1]
|
||||
ret int %tmp.12
|
||||
%tmp.3 = trunc i32 %sh to i8 ; <i8> [#uses=1]
|
||||
%tmp.4 = lshr i32 %x, %sh ; <i32> [#uses=2]
|
||||
%tmp.7 = sub i32 32, %sh ; <i32> [#uses=1]
|
||||
%tmp.10 = shl i32 %x, %tmp.7 ; <i32> [#uses=1]
|
||||
%tmp.12 = or i32 %tmp.4, %tmp.10 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.12
|
||||
}
|
||||
|
||||
int %rotlwi(uint %x) {
|
||||
define i32 @rotlwi(i32 %x) {
|
||||
entry:
|
||||
%x = cast uint %x to int ; <int> [#uses=1]
|
||||
%tmp.7 = shr uint %x, ubyte 27 ; <uint> [#uses=1]
|
||||
%tmp.3 = shl int %x, ubyte 5 ; <int> [#uses=1]
|
||||
%tmp.7 = cast uint %tmp.7 to int ; <int> [#uses=1]
|
||||
%tmp.9 = or int %tmp.3, %tmp.7 ; <int> [#uses=1]
|
||||
ret int %tmp.9
|
||||
%tmp.7 = lshr i32 %x, 27 ; <i32> [#uses=2]
|
||||
%tmp.3 = shl i32 %x, 5 ; <i32> [#uses=1]
|
||||
%tmp.9 = or i32 %tmp.3, %tmp.7 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.9
|
||||
}
|
||||
|
||||
int %rotrwi(uint %x) {
|
||||
define i32 @rotrwi(i32 %x) {
|
||||
entry:
|
||||
%tmp.3 = shr uint %x, ubyte 5 ; <uint> [#uses=1]
|
||||
%x = cast uint %x to int ; <int> [#uses=1]
|
||||
%tmp.3 = cast uint %tmp.3 to int ; <int> [#uses=1]
|
||||
%tmp.7 = shl int %x, ubyte 27 ; <int> [#uses=1]
|
||||
%tmp.9 = or int %tmp.3, %tmp.7 ; <int> [#uses=1]
|
||||
ret int %tmp.9
|
||||
%tmp.3 = lshr i32 %x, 5 ; <i32> [#uses=2]
|
||||
%tmp.7 = shl i32 %x, 27 ; <i32> [#uses=1]
|
||||
%tmp.9 = or i32 %tmp.3, %tmp.7 ; <i32> [#uses=1]
|
||||
ret i32 %tmp.9
|
||||
}
|
||||
|
@ -29,19 +29,19 @@ b:
|
||||
%r22 = select i1 %r20, i64 1, i64 %r19h
|
||||
%r23 = mul i64 %r22, 0
|
||||
%r23a = trunc i64 %r23 to i32
|
||||
%r24 = shl i32 %r23a, i8 0
|
||||
%r24 = shl i32 %r23a, 0
|
||||
%r25 = add i32 %r24, 0
|
||||
%ras2 = alloca i8, i32 %r25, align 16
|
||||
%r28 = getelementptr i8* %ras2, i32 0
|
||||
%r38 = shl i64 %r12, i8 0
|
||||
%r38 = shl i64 %r12, 0
|
||||
%s2013 = add i64 %r38, 0
|
||||
%c22012 = getelementptr i8* %ras2, i64 %s2013
|
||||
%r42 = shl i64 %r12, i8 0
|
||||
%r42 = shl i64 %r12, 0
|
||||
%s2011 = add i64 %r42, 16
|
||||
%c22010 = getelementptr i8* %ras2, i64 %s2011
|
||||
%r50 = add i64 %r16, 0
|
||||
%r51 = icmp slt i64 %r50, 0
|
||||
%r50sh = shl i64 %r50, i8 0
|
||||
%r50sh = shl i64 %r50, 0
|
||||
%r50j = add i64 %r50sh, 0
|
||||
%r54 = select i1 %r51, i64 0, i64 %r50j
|
||||
%r56 = mul i64 %r54, %r12
|
||||
@ -69,7 +69,7 @@ a25b140q:
|
||||
br label %a25b140
|
||||
a25b:
|
||||
%w1989 = phi i64 [ 0, %b63 ], [ %v1990, %a25b ]
|
||||
%e642 = shl i64 %w1989, i8 0
|
||||
%e642 = shl i64 %w1989, 0
|
||||
%r129 = add i64 %e642, 0
|
||||
%r132 = add i64 %e642, 0
|
||||
%r134 = icmp slt i64 %r132, 0
|
||||
@ -112,7 +112,7 @@ a30b294q:
|
||||
br label %a30b294
|
||||
a30b:
|
||||
%w = phi i64 [ 0, %b179 ], [ %v, %a30b ]
|
||||
%b2 = shl i64 %w, i8 0
|
||||
%b2 = shl i64 %w, 0
|
||||
%r283 = add i64 %b2, 0
|
||||
%r286 = add i64 %b2, 0
|
||||
%r288 = icmp slt i64 %r286, 0
|
||||
@ -152,7 +152,7 @@ b377:
|
||||
br i1 %r462, label %a35b465, label %b463
|
||||
a35b:
|
||||
%w1865 = phi i64 [ 0, %b341 ], [ %v1866, %a35b ]
|
||||
%e785 = shl i64 %w1865, i8 0
|
||||
%e785 = shl i64 %w1865, 0
|
||||
%b1877 = mul i64 %w1865, 0
|
||||
%s795 = add i64 %b1877, 0
|
||||
%r399 = add float %r354, 0.000000e+00
|
||||
@ -196,7 +196,7 @@ b565:
|
||||
br i1 %r711, label %a45b714, label %b712
|
||||
a45b:
|
||||
%w1852 = phi i64 [ 0, %b535 ], [ %v1853, %a45b ]
|
||||
%e945 = shl i64 %w1852, i8 0
|
||||
%e945 = shl i64 %w1852, 0
|
||||
%r609 = add i64 %r562, 0
|
||||
%r703 = add i64 %e945, 0
|
||||
%r706 = add i64 %e945, 0
|
||||
@ -261,7 +261,7 @@ b858:
|
||||
%w1891 = phi i64 [ 0, %b820 ], [ %v1892, %b1016 ]
|
||||
%s1193 = phi i64 [ 0, %b820 ], [ %r1068, %b1016 ]
|
||||
%b1894 = mul i64 %r834, 0
|
||||
%b1896 = shl i64 %r823, i8 0
|
||||
%b1896 = shl i64 %r823, 0
|
||||
%b1902 = mul i64 %w1891, 0
|
||||
%s1173 = add i64 %b1902, 0
|
||||
%r859 = add i64 %r856, 0
|
||||
@ -285,7 +285,7 @@ a53b1019q:
|
||||
br label %a53b1019
|
||||
a53b:
|
||||
%w1881 = phi i64 [ 0, %b858 ], [ %v1882, %a53b ]
|
||||
%e1205 = shl i64 %w1881, i8 0
|
||||
%e1205 = shl i64 %w1881, 0
|
||||
%r1007 = add i64 %e1205, 0
|
||||
%r1010 = add i64 %e1205, 0
|
||||
%r1012 = icmp slt i64 %r1010, 0
|
||||
@ -365,7 +365,7 @@ a63b:
|
||||
%b1907 = mul i64 %r1101, 0
|
||||
%b1929 = mul i64 %w1904, 0
|
||||
%s1395 = add i64 %b1929, 0
|
||||
%e1365 = shl i64 %w1904, i8 0
|
||||
%e1365 = shl i64 %w1904, 0
|
||||
%r1163 = add i64 %r1090, 0
|
||||
%r1167 = add i64 %s1375, 0
|
||||
%r1191 = add i64 %r1163, 0
|
||||
|
@ -12,8 +12,7 @@ define i1 @test1(i32 %X) zext {
|
||||
|
||||
define i1 @test2(i32 %val, i32 %mask) {
|
||||
entry:
|
||||
%maski8 = trunc i32 %mask to i8
|
||||
%shifted = ashr i32 %val, i8 %maski8
|
||||
%shifted = ashr i32 %val, %mask
|
||||
%anded = and i32 %shifted, 1
|
||||
%trunced = trunc i32 %anded to i1
|
||||
br i1 %trunced, label %ret_true, label %ret_false
|
||||
|
@ -14,11 +14,12 @@ begin
|
||||
%t3 = sext i31 %i to i33
|
||||
%t4 = or i33 %t3, %j
|
||||
%t5 = xor i31 %t2, 7
|
||||
%t6 = shl i31 %i, i8 2
|
||||
%t6 = shl i31 %i, 2
|
||||
%t7 = trunc i31 %i to i8
|
||||
%t8 = shl i8 %t7, i8 3
|
||||
%t9 = lshr i33 %j, i8 31
|
||||
%t10 = ashr i33 %j, i8 %t7
|
||||
%t8 = shl i8 %t7, 3
|
||||
%t9 = lshr i33 %j, 31
|
||||
%t7z = zext i8 %t7 to i33
|
||||
%t10 = ashr i33 %j, %t7z
|
||||
ret void
|
||||
end
|
||||
|
||||
|
@ -10,10 +10,10 @@
|
||||
@f = constant i1 sub(i1 1 , i1 -1)
|
||||
@g = constant i1 sub(i1 1 , i1 1)
|
||||
|
||||
@h = constant i1 shl(i1 1 , i8 1)
|
||||
@i = constant i1 shl(i1 1 , i8 0)
|
||||
@j = constant i1 lshr(i1 1, i8 1)
|
||||
@m = constant i1 ashr(i1 1, i8 1)
|
||||
@h = constant i1 shl(i1 1 , i1 1)
|
||||
@i = constant i1 shl(i1 1 , i1 0)
|
||||
@j = constant i1 lshr(i1 1, i1 1)
|
||||
@m = constant i1 ashr(i1 1, i1 1)
|
||||
|
||||
@n = constant i1 mul(i1 -1, i1 1)
|
||||
@o = constant i1 sdiv(i1 -1, i1 1)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i15 sub(i15 0 , i15 32767)
|
||||
@g = constant i15 sub(i15 2 , i15 32767)
|
||||
|
||||
@h = constant i15 shl(i15 1 , i8 15)
|
||||
@i = constant i15 shl(i15 1 , i8 14)
|
||||
@j = constant i15 lshr(i15 32767 , i8 14)
|
||||
@k = constant i15 lshr(i15 32767 , i8 15)
|
||||
@l = constant i15 ashr(i15 32767 , i8 14)
|
||||
@m = constant i15 ashr(i15 32767 , i8 15)
|
||||
@h = constant i15 shl(i15 1 , i15 15)
|
||||
@i = constant i15 shl(i15 1 , i15 14)
|
||||
@j = constant i15 lshr(i15 32767 , i15 14)
|
||||
@k = constant i15 lshr(i15 32767 , i15 15)
|
||||
@l = constant i15 ashr(i15 32767 , i15 14)
|
||||
@m = constant i15 ashr(i15 32767 , i15 15)
|
||||
|
||||
@n = constant i15 mul(i15 32767, i15 2)
|
||||
@q = constant i15 mul(i15 -16383,i15 -3)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i17 sub(i17 0 , i17 131071)
|
||||
@g = constant i17 sub(i17 2 , i17 131071)
|
||||
|
||||
@h = constant i17 shl(i17 1 , i8 17)
|
||||
@i = constant i17 shl(i17 1 , i8 16)
|
||||
@j = constant i17 lshr(i17 131071 , i8 16)
|
||||
@k = constant i17 lshr(i17 131071 , i8 17)
|
||||
@l = constant i17 ashr(i17 131071 , i8 16)
|
||||
@m = constant i17 ashr(i17 131071 , i8 17)
|
||||
@h = constant i17 shl(i17 1 , i17 17)
|
||||
@i = constant i17 shl(i17 1 , i17 16)
|
||||
@j = constant i17 lshr(i17 131071 , i17 16)
|
||||
@k = constant i17 lshr(i17 131071 , i17 17)
|
||||
@l = constant i17 ashr(i17 131071 , i17 16)
|
||||
@m = constant i17 ashr(i17 131071 , i17 17)
|
||||
|
||||
@n = constant i17 mul(i17 131071, i17 2)
|
||||
@q = constant i17 sdiv(i17 -1, i17 65535)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i31 sub(i31 0 , i31 2147483647)
|
||||
@g = constant i31 sub(i31 2 , i31 2147483647)
|
||||
|
||||
@h = constant i31 shl(i31 1 , i8 31)
|
||||
@i = constant i31 shl(i31 1 , i8 30)
|
||||
@j = constant i31 lshr(i31 2147483647 , i8 30)
|
||||
@k = constant i31 lshr(i31 2147483647 , i8 31)
|
||||
@l = constant i31 ashr(i31 2147483647 , i8 30)
|
||||
@m = constant i31 ashr(i31 2147483647 , i8 31)
|
||||
@h = constant i31 shl(i31 1 , i31 31)
|
||||
@i = constant i31 shl(i31 1 , i31 30)
|
||||
@j = constant i31 lshr(i31 2147483647 , i31 30)
|
||||
@k = constant i31 lshr(i31 2147483647 , i31 31)
|
||||
@l = constant i31 ashr(i31 2147483647 , i31 30)
|
||||
@m = constant i31 ashr(i31 2147483647 , i31 31)
|
||||
|
||||
@n = constant i31 mul(i31 2147483647, i31 2)
|
||||
@q = constant i31 sdiv(i31 -1, i31 1073741823)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i33 sub(i33 0 , i33 8589934591)
|
||||
@g = constant i33 sub(i33 2 , i33 8589934591)
|
||||
|
||||
@h = constant i33 shl(i33 1 , i8 33)
|
||||
@i = constant i33 shl(i33 1 , i8 32)
|
||||
@j = constant i33 lshr(i33 8589934591 , i8 32)
|
||||
@k = constant i33 lshr(i33 8589934591 , i8 33)
|
||||
@l = constant i33 ashr(i33 8589934591 , i8 32)
|
||||
@m = constant i33 ashr(i33 8589934591 , i8 33)
|
||||
@h = constant i33 shl(i33 1 , i33 33)
|
||||
@i = constant i33 shl(i33 1 , i33 32)
|
||||
@j = constant i33 lshr(i33 8589934591 , i33 32)
|
||||
@k = constant i33 lshr(i33 8589934591 , i33 33)
|
||||
@l = constant i33 ashr(i33 8589934591 , i33 32)
|
||||
@m = constant i33 ashr(i33 8589934591 , i33 33)
|
||||
|
||||
@n = constant i33 mul(i33 8589934591, i33 2)
|
||||
@q = constant i33 sdiv(i33 -1, i33 4294967295)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i63 sub(i63 0 , i63 9223372036854775807)
|
||||
@g = constant i63 sub(i63 2 , i63 9223372036854775807)
|
||||
|
||||
@h = constant i63 shl(i63 1 , i8 63)
|
||||
@i = constant i63 shl(i63 1 , i8 62)
|
||||
@j = constant i63 lshr(i63 9223372036854775807 , i8 62)
|
||||
@k = constant i63 lshr(i63 9223372036854775807 , i8 63)
|
||||
@l = constant i63 ashr(i63 9223372036854775807 , i8 62)
|
||||
@m = constant i63 ashr(i63 9223372036854775807 , i8 63)
|
||||
@h = constant i63 shl(i63 1 , i63 63)
|
||||
@i = constant i63 shl(i63 1 , i63 62)
|
||||
@j = constant i63 lshr(i63 9223372036854775807 , i63 62)
|
||||
@k = constant i63 lshr(i63 9223372036854775807 , i63 63)
|
||||
@l = constant i63 ashr(i63 9223372036854775807 , i63 62)
|
||||
@m = constant i63 ashr(i63 9223372036854775807 , i63 63)
|
||||
|
||||
@n = constant i63 mul(i63 9223372036854775807, i63 2)
|
||||
@q = constant i63 sdiv(i63 -1, i63 4611686018427387903)
|
||||
|
@ -13,13 +13,13 @@
|
||||
@r = constant i7 sub(i7 -3, i7 120)
|
||||
@s = constant i7 sub(i7 -3, i7 -8)
|
||||
|
||||
@h = constant i7 shl(i7 1 , i8 7)
|
||||
@i = constant i7 shl(i7 1 , i8 6)
|
||||
@j = constant i7 lshr(i7 127 , i8 6)
|
||||
@k = constant i7 lshr(i7 127 , i8 7)
|
||||
@l = constant i7 ashr(i7 127 , i8 6)
|
||||
@m = constant i7 ashr(i7 127 , i8 7)
|
||||
@m2= constant i7 ashr(i7 -1 , i8 3)
|
||||
@h = constant i7 shl(i7 1 , i7 7)
|
||||
@i = constant i7 shl(i7 1 , i7 6)
|
||||
@j = constant i7 lshr(i7 127 , i7 6)
|
||||
@k = constant i7 lshr(i7 127 , i7 7)
|
||||
@l = constant i7 ashr(i7 127 , i7 6)
|
||||
@m = constant i7 ashr(i7 127 , i7 7)
|
||||
@m2= constant i7 ashr(i7 -1 , i7 3)
|
||||
|
||||
@n = constant i7 mul(i7 127, i7 2)
|
||||
@t = constant i7 mul(i7 -63, i7 -2)
|
||||
|
@ -10,12 +10,12 @@
|
||||
@f = constant i9 sub(i9 0 , i9 511)
|
||||
@g = constant i9 sub(i9 2 , i9 511)
|
||||
|
||||
@h = constant i9 shl(i9 1 , i8 9)
|
||||
@i = constant i9 shl(i9 1 , i8 8)
|
||||
@j = constant i9 lshr(i9 511 , i8 8)
|
||||
@k = constant i9 lshr(i9 511 , i8 9)
|
||||
@l = constant i9 ashr(i9 511 , i8 8)
|
||||
@m = constant i9 ashr(i9 511 , i8 9)
|
||||
@h = constant i9 shl(i9 1 , i9 9)
|
||||
@i = constant i9 shl(i9 1 , i9 8)
|
||||
@j = constant i9 lshr(i9 511 , i9 8)
|
||||
@k = constant i9 lshr(i9 511 , i9 9)
|
||||
@l = constant i9 ashr(i9 511 , i9 8)
|
||||
@m = constant i9 ashr(i9 511 , i9 9)
|
||||
|
||||
@n = constant i9 mul(i9 511, i9 2)
|
||||
@q = constant i9 sdiv(i9 511, i9 2)
|
||||
|
@ -13,9 +13,9 @@ begin
|
||||
%t5 = sdiv i31 %t1, %t2
|
||||
%t6 = urem i31 %t1, %t2
|
||||
%t7 = srem i31 %t1, %t2
|
||||
%t8 = shl i31 %t1, i8 9
|
||||
%t9 = lshr i31 %t1, i8 9
|
||||
%t10= ashr i31 %t1, i8 9
|
||||
%t8 = shl i31 %t1, 9
|
||||
%t9 = lshr i31 %t1, 9
|
||||
%t10= ashr i31 %t1, 9
|
||||
%f1 = sitofp i31 %t1 to float
|
||||
%f2 = fdiv float 4.0, %f1
|
||||
ret i31 %t3
|
||||
|
@ -9,8 +9,8 @@ begin
|
||||
%t1 = xor i31 %i0, %j0
|
||||
%t2 = or i31 %i0, %j0
|
||||
%t3 = and i31 %t1, %t2
|
||||
%t4 = shl i31 %i0, i8 2
|
||||
%t5 = ashr i31 %i0, i8 2
|
||||
%t6 = lshr i31 %j0, i8 22
|
||||
%t4 = shl i31 %i0, 2
|
||||
%t5 = ashr i31 %i0, 2
|
||||
%t6 = lshr i31 %j0, 22
|
||||
ret i31 %t3
|
||||
end
|
||||
|
@ -1,7 +1,8 @@
|
||||
; This test makes sure that add instructions are properly eliminated.
|
||||
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v OK | not grep add
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
|
||||
; RUN: grep -v OK | not grep add
|
||||
|
||||
implementation
|
||||
|
||||
@ -46,7 +47,8 @@ int %test7(int %A) {
|
||||
ret int %C
|
||||
}
|
||||
|
||||
int %test8(int %A, int %B) { ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
|
||||
; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
|
||||
int %test8(int %A, int %B) {
|
||||
%A1 = and int %A, 7
|
||||
%B1 = and int %B, 128
|
||||
%C = add int %A1, %B1
|
||||
|
@ -1,22 +1,23 @@
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | egrep 'shl|lshr|ashr' | wc -l | grep 3
|
||||
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
|
||||
; RUN: egrep 'shl|lshr|ashr' | wc -l | grep 3
|
||||
|
||||
int %test0(int %A, int %B, ubyte %C) {
|
||||
%X = shl int %A, ubyte %C
|
||||
%Y = shl int %B, ubyte %C
|
||||
%Z = and int %X, %Y
|
||||
ret int %Z
|
||||
define i32 @test0(i32 %A, i32 %B, i32 %C) {
|
||||
%X = shl i32 %A, %C
|
||||
%Y = shl i32 %B, %C
|
||||
%Z = and i32 %X, %Y
|
||||
ret i32 %Z
|
||||
}
|
||||
|
||||
int %test1(int %A, int %B, ubyte %C) {
|
||||
%X = lshr int %A, ubyte %C
|
||||
%Y = lshr int %B, ubyte %C
|
||||
%Z = or int %X, %Y
|
||||
ret int %Z
|
||||
define i32 @test1(i32 %A, i32 %B, i32 %C) {
|
||||
%X = lshr i32 %A, %C
|
||||
%Y = lshr i32 %B, %C
|
||||
%Z = or i32 %X, %Y
|
||||
ret i32 %Z
|
||||
}
|
||||
|
||||
int %test2(int %A, int %B, ubyte %C) {
|
||||
%X = ashr int %A, ubyte %C
|
||||
%Y = ashr int %B, ubyte %C
|
||||
%Z = xor int %X, %Y
|
||||
ret int %Z
|
||||
define i32 @test2(i32 %A, i32 %B, i32 %C) {
|
||||
%X = ashr i32 %A, %C
|
||||
%Y = ashr i32 %B, %C
|
||||
%Z = xor i32 %X, %Y
|
||||
ret i32 %Z
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep 'lshr i32' | wc -l | grep 2 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
|
||||
; RUN: grep 'lshr i32' | wc -l | grep 2 &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep ashr
|
||||
|
||||
int %test1(int %X, ubyte %A) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep '(and\|xor\|add\|shl\|shr)'
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
|
||||
; RUN: not grep '(and\|xor\|add\|shl\|shr)'
|
||||
|
||||
int %test1(int %x) {
|
||||
%tmp.1 = and int %x, 65535 ; <int> [#uses=1]
|
||||
|
@ -1,6 +1,6 @@
|
||||
; With shl->mul reassociation, we can see that this is (shl A, 9) * A
|
||||
;
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | grep 'shl .*, i8 9'
|
||||
; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | grep 'shl .*, 9'
|
||||
|
||||
int %test(int %A, int %B) {
|
||||
%X = shl int %A, ubyte 5
|
||||
|
@ -194,6 +194,7 @@ enum BinaryOps {
|
||||
DivOp, UDivOp, SDivOp, FDivOp,
|
||||
RemOp, URemOp, SRemOp, FRemOp,
|
||||
AndOp, OrOp, XorOp,
|
||||
ShlOp, ShrOp, LShrOp, AShrOp,
|
||||
SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT
|
||||
};
|
||||
|
||||
@ -202,10 +203,9 @@ enum MemoryOps {
|
||||
};
|
||||
|
||||
enum OtherOps {
|
||||
PHIOp, CallOp, ShlOp, ShrOp, SelectOp, UserOp1, UserOp2, VAArg,
|
||||
PHIOp, CallOp, SelectOp, UserOp1, UserOp2, VAArg,
|
||||
ExtractElementOp, InsertElementOp, ShuffleVectorOp,
|
||||
ICmpOp, FCmpOp,
|
||||
LShrOp, AShrOp
|
||||
ICmpOp, FCmpOp
|
||||
};
|
||||
|
||||
enum CastOps {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -274,6 +274,11 @@ setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); }
|
||||
setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); }
|
||||
setle { RET_TOK(BinaryOpVal, SetLE, SETLE); }
|
||||
setge { RET_TOK(BinaryOpVal, SetGE, SETGE); }
|
||||
shl { RET_TOK(BinaryOpVal, ShlOp, SHL); }
|
||||
shr { RET_TOK(BinaryOpVal, ShrOp, SHR); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShrOp, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShrOp, ASHR); }
|
||||
|
||||
icmp { RET_TOK(OtherOpVal, ICmpOp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmpOp, FCMP); }
|
||||
|
||||
@ -314,10 +319,6 @@ ptrtoint { RET_TOK(CastOpVal, PtrToIntOp, PTRTOINT); }
|
||||
inttoptr { RET_TOK(CastOpVal, IntToPtrOp, INTTOPTR); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCastOp, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, SelectOp, SELECT); }
|
||||
shl { RET_TOK(OtherOpVal, ShlOp, SHL); }
|
||||
shr { RET_TOK(OtherOpVal, ShrOp, SHR); }
|
||||
lshr { RET_TOK(OtherOpVal, LShrOp, LSHR); }
|
||||
ashr { RET_TOK(OtherOpVal, AShrOp, ASHR); }
|
||||
vanext { return VANEXT_old; }
|
||||
vaarg { return VAARG_old; }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
|
@ -274,6 +274,11 @@ setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); }
|
||||
setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); }
|
||||
setle { RET_TOK(BinaryOpVal, SetLE, SETLE); }
|
||||
setge { RET_TOK(BinaryOpVal, SetGE, SETGE); }
|
||||
shl { RET_TOK(BinaryOpVal, ShlOp, SHL); }
|
||||
shr { RET_TOK(BinaryOpVal, ShrOp, SHR); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShrOp, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShrOp, ASHR); }
|
||||
|
||||
icmp { RET_TOK(OtherOpVal, ICmpOp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmpOp, FCMP); }
|
||||
|
||||
@ -314,10 +319,6 @@ ptrtoint { RET_TOK(CastOpVal, PtrToIntOp, PTRTOINT); }
|
||||
inttoptr { RET_TOK(CastOpVal, IntToPtrOp, INTTOPTR); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCastOp, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, SelectOp, SELECT); }
|
||||
shl { RET_TOK(OtherOpVal, ShlOp, SHL); }
|
||||
shr { RET_TOK(OtherOpVal, ShrOp, SHR); }
|
||||
lshr { RET_TOK(OtherOpVal, LShrOp, LSHR); }
|
||||
ashr { RET_TOK(OtherOpVal, AShrOp, ASHR); }
|
||||
vanext { return VANEXT_old; }
|
||||
vaarg { return VAARG_old; }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -119,26 +119,26 @@
|
||||
AND = 345,
|
||||
OR = 346,
|
||||
XOR = 347,
|
||||
SETLE = 348,
|
||||
SETGE = 349,
|
||||
SETLT = 350,
|
||||
SETGT = 351,
|
||||
SETEQ = 352,
|
||||
SETNE = 353,
|
||||
ICMP = 354,
|
||||
FCMP = 355,
|
||||
MALLOC = 356,
|
||||
ALLOCA = 357,
|
||||
FREE = 358,
|
||||
LOAD = 359,
|
||||
STORE = 360,
|
||||
GETELEMENTPTR = 361,
|
||||
PHI_TOK = 362,
|
||||
SELECT = 363,
|
||||
SHL = 364,
|
||||
SHR = 365,
|
||||
ASHR = 366,
|
||||
LSHR = 367,
|
||||
SHL = 348,
|
||||
SHR = 349,
|
||||
ASHR = 350,
|
||||
LSHR = 351,
|
||||
SETLE = 352,
|
||||
SETGE = 353,
|
||||
SETLT = 354,
|
||||
SETGT = 355,
|
||||
SETEQ = 356,
|
||||
SETNE = 357,
|
||||
ICMP = 358,
|
||||
FCMP = 359,
|
||||
MALLOC = 360,
|
||||
ALLOCA = 361,
|
||||
FREE = 362,
|
||||
LOAD = 363,
|
||||
STORE = 364,
|
||||
GETELEMENTPTR = 365,
|
||||
PHI_TOK = 366,
|
||||
SELECT = 367,
|
||||
VAARG = 368,
|
||||
EXTRACTELEMENT = 369,
|
||||
INSERTELEMENT = 370,
|
||||
@ -271,26 +271,26 @@
|
||||
#define AND 345
|
||||
#define OR 346
|
||||
#define XOR 347
|
||||
#define SETLE 348
|
||||
#define SETGE 349
|
||||
#define SETLT 350
|
||||
#define SETGT 351
|
||||
#define SETEQ 352
|
||||
#define SETNE 353
|
||||
#define ICMP 354
|
||||
#define FCMP 355
|
||||
#define MALLOC 356
|
||||
#define ALLOCA 357
|
||||
#define FREE 358
|
||||
#define LOAD 359
|
||||
#define STORE 360
|
||||
#define GETELEMENTPTR 361
|
||||
#define PHI_TOK 362
|
||||
#define SELECT 363
|
||||
#define SHL 364
|
||||
#define SHR 365
|
||||
#define ASHR 366
|
||||
#define LSHR 367
|
||||
#define SHL 348
|
||||
#define SHR 349
|
||||
#define ASHR 350
|
||||
#define LSHR 351
|
||||
#define SETLE 352
|
||||
#define SETGE 353
|
||||
#define SETLT 354
|
||||
#define SETGT 355
|
||||
#define SETEQ 356
|
||||
#define SETNE 357
|
||||
#define ICMP 358
|
||||
#define FCMP 359
|
||||
#define MALLOC 360
|
||||
#define ALLOCA 361
|
||||
#define FREE 362
|
||||
#define LOAD 363
|
||||
#define STORE 364
|
||||
#define GETELEMENTPTR 365
|
||||
#define PHI_TOK 366
|
||||
#define SELECT 367
|
||||
#define VAARG 368
|
||||
#define EXTRACTELEMENT 369
|
||||
#define INSERTELEMENT 370
|
||||
@ -335,7 +335,7 @@
|
||||
|
||||
|
||||
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
|
||||
#line 1440 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
|
||||
#line 1435 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
|
||||
typedef union YYSTYPE {
|
||||
llvm::Module *ModuleVal;
|
||||
llvm::Function *FunctionVal;
|
||||
|
@ -1008,6 +1008,13 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) {
|
||||
case URemOp : return Instruction::URem;
|
||||
case SRemOp : return Instruction::SRem;
|
||||
case FRemOp : return Instruction::FRem;
|
||||
case LShrOp : return Instruction::LShr;
|
||||
case AShrOp : return Instruction::AShr;
|
||||
case ShlOp : return Instruction::Shl;
|
||||
case ShrOp :
|
||||
if (Sign == Signed)
|
||||
return Instruction::AShr;
|
||||
return Instruction::LShr;
|
||||
case AndOp : return Instruction::And;
|
||||
case OrOp : return Instruction::Or;
|
||||
case XorOp : return Instruction::Xor;
|
||||
@ -1102,11 +1109,6 @@ getOtherOp(OtherOps op, Signedness Sign) {
|
||||
default : assert(0 && "Invalid OldOtherOps");
|
||||
case PHIOp : return Instruction::PHI;
|
||||
case CallOp : return Instruction::Call;
|
||||
case ShlOp : return Instruction::Shl;
|
||||
case ShrOp :
|
||||
if (Sign == Signed)
|
||||
return Instruction::AShr;
|
||||
return Instruction::LShr;
|
||||
case SelectOp : return Instruction::Select;
|
||||
case UserOp1 : return Instruction::UserOp1;
|
||||
case UserOp2 : return Instruction::UserOp2;
|
||||
@ -1116,8 +1118,6 @@ getOtherOp(OtherOps op, Signedness Sign) {
|
||||
case ShuffleVectorOp : return Instruction::ShuffleVector;
|
||||
case ICmpOp : return Instruction::ICmp;
|
||||
case FCmpOp : return Instruction::FCmp;
|
||||
case LShrOp : return Instruction::LShr;
|
||||
case AShrOp : return Instruction::AShr;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1193,7 +1193,6 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
error("Invalid prototype for " + Name + " prototype");
|
||||
return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
|
||||
} else {
|
||||
static unsigned upgradeCount = 1;
|
||||
const Type* PtrTy = PointerType::get(Type::Int8Ty);
|
||||
std::vector<const Type*> Params;
|
||||
if (Name == "llvm.va_start" || Name == "llvm.va_end") {
|
||||
@ -1203,9 +1202,7 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
|
||||
const PointerType *PFTy = PointerType::get(FTy);
|
||||
Value* Func = getVal(PFTy, ID);
|
||||
std::string InstName("va_upgrade");
|
||||
InstName += llvm::utostr(upgradeCount++);
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, InstName, CurBB);
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
|
||||
return new CallInst(Func, Args);
|
||||
} else if (Name == "llvm.va_copy") {
|
||||
if (Args.size() != 2)
|
||||
@ -1215,10 +1212,8 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
|
||||
const PointerType *PFTy = PointerType::get(FTy);
|
||||
Value* Func = getVal(PFTy, ID);
|
||||
std::string InstName0("va_upgrade");
|
||||
InstName0 += llvm::utostr(upgradeCount++);
|
||||
std::string InstName1("va_upgrade");
|
||||
InstName1 += llvm::utostr(upgradeCount++);
|
||||
std::string InstName0(makeNameUnique("va0"));
|
||||
std::string InstName1(makeNameUnique("va1"));
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
|
||||
Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
|
||||
return new CallInst(Func, Args);
|
||||
@ -1263,7 +1258,7 @@ const Type* upgradeGEPIndices(const Type* PTy,
|
||||
cast<Constant>(Index), Type::Int64Ty);
|
||||
else
|
||||
Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
|
||||
makeNameUnique("gep_upgrade"), CurBB);
|
||||
makeNameUnique("gep"), CurBB);
|
||||
VIndices[i] = Index;
|
||||
}
|
||||
}
|
||||
@ -1546,8 +1541,9 @@ using namespace llvm;
|
||||
|
||||
// Binary Operators
|
||||
%type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
|
||||
%type <BinaryOpVal> ShiftOps
|
||||
%token <BinaryOpVal> ADD SUB MUL DIV UDIV SDIV FDIV REM UREM SREM FREM
|
||||
%token <BinaryOpVal> AND OR XOR
|
||||
%token <BinaryOpVal> AND OR XOR SHL SHR ASHR LSHR
|
||||
%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
|
||||
%token <OtherOpVal> ICMP FCMP
|
||||
|
||||
@ -1555,8 +1551,7 @@ using namespace llvm;
|
||||
%token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
|
||||
|
||||
// Other Operators
|
||||
%type <OtherOpVal> ShiftOps
|
||||
%token <OtherOpVal> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
%token VAARG_old VANEXT_old //OBSOLETE
|
||||
|
||||
@ -2303,9 +2298,11 @@ ConstExpr
|
||||
if (!$5.C->getType()->isInteger() ||
|
||||
cast<IntegerType>($5.C->getType())->getBitWidth() != 8)
|
||||
error("Shift count for shift constant must be unsigned byte");
|
||||
const Type* Ty = $3.C->getType();
|
||||
if (!$3.C->getType()->isInteger())
|
||||
error("Shift constant expression requires integer operand");
|
||||
$$.C = ConstantExpr::get(getOtherOp($1, $3.S), $3.C, $5.C);
|
||||
Constant *ShiftAmt = ConstantExpr::getZExt($5.C, Ty);
|
||||
$$.C = ConstantExpr::get(getBinaryOp($1, Ty, $3.S), $3.C, ShiftAmt);
|
||||
$$.S = $3.S;
|
||||
}
|
||||
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
|
||||
@ -3118,9 +3115,18 @@ InstVal
|
||||
if (!$4.V->getType()->isInteger() ||
|
||||
cast<IntegerType>($4.V->getType())->getBitWidth() != 8)
|
||||
error("Shift amount must be int8");
|
||||
if (!$2.V->getType()->isInteger())
|
||||
const Type* Ty = $2.V->getType();
|
||||
if (!Ty->isInteger())
|
||||
error("Shift constant expression requires integer operand");
|
||||
$$.I = new ShiftInst(getOtherOp($1, $2.S), $2.V, $4.V);
|
||||
Value* ShiftAmt = 0;
|
||||
if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
|
||||
if (Constant *C = dyn_cast<Constant>($4.V))
|
||||
ShiftAmt = ConstantExpr::getZExt(C, Ty);
|
||||
else
|
||||
ShiftAmt = new ZExtInst($4.V, Ty, makeNameUnique("shift"), CurBB);
|
||||
else
|
||||
ShiftAmt = $4.V;
|
||||
$$.I = BinaryOperator::create(getBinaryOp($1, Ty, $2.S), $2.V, ShiftAmt);
|
||||
$$.S = $2.S;
|
||||
}
|
||||
| CastOps ResolvedVal TO Types {
|
||||
|
@ -1008,6 +1008,13 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) {
|
||||
case URemOp : return Instruction::URem;
|
||||
case SRemOp : return Instruction::SRem;
|
||||
case FRemOp : return Instruction::FRem;
|
||||
case LShrOp : return Instruction::LShr;
|
||||
case AShrOp : return Instruction::AShr;
|
||||
case ShlOp : return Instruction::Shl;
|
||||
case ShrOp :
|
||||
if (Sign == Signed)
|
||||
return Instruction::AShr;
|
||||
return Instruction::LShr;
|
||||
case AndOp : return Instruction::And;
|
||||
case OrOp : return Instruction::Or;
|
||||
case XorOp : return Instruction::Xor;
|
||||
@ -1102,11 +1109,6 @@ getOtherOp(OtherOps op, Signedness Sign) {
|
||||
default : assert(0 && "Invalid OldOtherOps");
|
||||
case PHIOp : return Instruction::PHI;
|
||||
case CallOp : return Instruction::Call;
|
||||
case ShlOp : return Instruction::Shl;
|
||||
case ShrOp :
|
||||
if (Sign == Signed)
|
||||
return Instruction::AShr;
|
||||
return Instruction::LShr;
|
||||
case SelectOp : return Instruction::Select;
|
||||
case UserOp1 : return Instruction::UserOp1;
|
||||
case UserOp2 : return Instruction::UserOp2;
|
||||
@ -1116,8 +1118,6 @@ getOtherOp(OtherOps op, Signedness Sign) {
|
||||
case ShuffleVectorOp : return Instruction::ShuffleVector;
|
||||
case ICmpOp : return Instruction::ICmp;
|
||||
case FCmpOp : return Instruction::FCmp;
|
||||
case LShrOp : return Instruction::LShr;
|
||||
case AShrOp : return Instruction::AShr;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1193,7 +1193,6 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
error("Invalid prototype for " + Name + " prototype");
|
||||
return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
|
||||
} else {
|
||||
static unsigned upgradeCount = 1;
|
||||
const Type* PtrTy = PointerType::get(Type::Int8Ty);
|
||||
std::vector<const Type*> Params;
|
||||
if (Name == "llvm.va_start" || Name == "llvm.va_end") {
|
||||
@ -1203,9 +1202,7 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
|
||||
const PointerType *PFTy = PointerType::get(FTy);
|
||||
Value* Func = getVal(PFTy, ID);
|
||||
std::string InstName("va_upgrade");
|
||||
InstName += llvm::utostr(upgradeCount++);
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, InstName, CurBB);
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
|
||||
return new CallInst(Func, Args);
|
||||
} else if (Name == "llvm.va_copy") {
|
||||
if (Args.size() != 2)
|
||||
@ -1215,10 +1212,8 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
|
||||
const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
|
||||
const PointerType *PFTy = PointerType::get(FTy);
|
||||
Value* Func = getVal(PFTy, ID);
|
||||
std::string InstName0("va_upgrade");
|
||||
InstName0 += llvm::utostr(upgradeCount++);
|
||||
std::string InstName1("va_upgrade");
|
||||
InstName1 += llvm::utostr(upgradeCount++);
|
||||
std::string InstName0(makeNameUnique("va0"));
|
||||
std::string InstName1(makeNameUnique("va1"));
|
||||
Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
|
||||
Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
|
||||
return new CallInst(Func, Args);
|
||||
@ -1263,7 +1258,7 @@ const Type* upgradeGEPIndices(const Type* PTy,
|
||||
cast<Constant>(Index), Type::Int64Ty);
|
||||
else
|
||||
Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
|
||||
makeNameUnique("gep_upgrade"), CurBB);
|
||||
makeNameUnique("gep"), CurBB);
|
||||
VIndices[i] = Index;
|
||||
}
|
||||
}
|
||||
@ -1546,8 +1541,9 @@ using namespace llvm;
|
||||
|
||||
// Binary Operators
|
||||
%type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
|
||||
%type <BinaryOpVal> ShiftOps
|
||||
%token <BinaryOpVal> ADD SUB MUL DIV UDIV SDIV FDIV REM UREM SREM FREM
|
||||
%token <BinaryOpVal> AND OR XOR
|
||||
%token <BinaryOpVal> AND OR XOR SHL SHR ASHR LSHR
|
||||
%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
|
||||
%token <OtherOpVal> ICMP FCMP
|
||||
|
||||
@ -1555,8 +1551,7 @@ using namespace llvm;
|
||||
%token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
|
||||
|
||||
// Other Operators
|
||||
%type <OtherOpVal> ShiftOps
|
||||
%token <OtherOpVal> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
%token VAARG_old VANEXT_old //OBSOLETE
|
||||
|
||||
@ -2303,9 +2298,11 @@ ConstExpr
|
||||
if (!$5.C->getType()->isInteger() ||
|
||||
cast<IntegerType>($5.C->getType())->getBitWidth() != 8)
|
||||
error("Shift count for shift constant must be unsigned byte");
|
||||
const Type* Ty = $3.C->getType();
|
||||
if (!$3.C->getType()->isInteger())
|
||||
error("Shift constant expression requires integer operand");
|
||||
$$.C = ConstantExpr::get(getOtherOp($1, $3.S), $3.C, $5.C);
|
||||
Constant *ShiftAmt = ConstantExpr::getZExt($5.C, Ty);
|
||||
$$.C = ConstantExpr::get(getBinaryOp($1, Ty, $3.S), $3.C, ShiftAmt);
|
||||
$$.S = $3.S;
|
||||
}
|
||||
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
|
||||
@ -3118,9 +3115,18 @@ InstVal
|
||||
if (!$4.V->getType()->isInteger() ||
|
||||
cast<IntegerType>($4.V->getType())->getBitWidth() != 8)
|
||||
error("Shift amount must be int8");
|
||||
if (!$2.V->getType()->isInteger())
|
||||
const Type* Ty = $2.V->getType();
|
||||
if (!Ty->isInteger())
|
||||
error("Shift constant expression requires integer operand");
|
||||
$$.I = new ShiftInst(getOtherOp($1, $2.S), $2.V, $4.V);
|
||||
Value* ShiftAmt = 0;
|
||||
if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
|
||||
if (Constant *C = dyn_cast<Constant>($4.V))
|
||||
ShiftAmt = ConstantExpr::getZExt(C, Ty);
|
||||
else
|
||||
ShiftAmt = new ZExtInst($4.V, Ty, makeNameUnique("shift"), CurBB);
|
||||
else
|
||||
ShiftAmt = $4.V;
|
||||
$$.I = BinaryOperator::create(getBinaryOp($1, Ty, $2.S), $2.V, ShiftAmt);
|
||||
$$.S = $2.S;
|
||||
}
|
||||
| CastOps ResolvedVal TO Types {
|
||||
|
Loading…
x
Reference in New Issue
Block a user