summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r--llvm/lib/VMCore/ConstantFolding.cpp62
-rw-r--r--llvm/lib/VMCore/Constants.cpp37
-rw-r--r--llvm/lib/VMCore/Instruction.cpp3
-rw-r--r--llvm/lib/VMCore/Instructions.cpp11
4 files changed, 52 insertions, 61 deletions
diff --git a/llvm/lib/VMCore/ConstantFolding.cpp b/llvm/lib/VMCore/ConstantFolding.cpp
index 055d41c063d..28993d52247 100644
--- a/llvm/lib/VMCore/ConstantFolding.cpp
+++ b/llvm/lib/VMCore/ConstantFolding.cpp
@@ -50,7 +50,8 @@ namespace {
virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0;
virtual Constant *op_xor(const Constant *V1, const Constant *V2) const = 0;
virtual Constant *shl(const Constant *V1, const Constant *V2) const = 0;
- virtual Constant *shr(const Constant *V1, const Constant *V2) const = 0;
+ virtual Constant *lshr(const Constant *V1, const Constant *V2) const = 0;
+ virtual Constant *ashr(const Constant *V1, const Constant *V2) const = 0;
virtual Constant *lessthan(const Constant *V1, const Constant *V2) const =0;
virtual Constant *equalto(const Constant *V1, const Constant *V2) const = 0;
@@ -140,8 +141,11 @@ class VISIBILITY_HIDDEN TemplateRules : public ConstRules {
virtual Constant *shl(const Constant *V1, const Constant *V2) const {
return SubClassName::Shl((const ArgType *)V1, (const ArgType *)V2);
}
- virtual Constant *shr(const Constant *V1, const Constant *V2) const {
- return SubClassName::Shr((const ArgType *)V1, (const ArgType *)V2);
+ virtual Constant *lshr(const Constant *V1, const Constant *V2) const {
+ return SubClassName::LShr((const ArgType *)V1, (const ArgType *)V2);
+ }
+ virtual Constant *ashr(const Constant *V1, const Constant *V2) const {
+ return SubClassName::AShr((const ArgType *)V1, (const ArgType *)V2);
}
virtual Constant *lessthan(const Constant *V1, const Constant *V2) const {
@@ -207,7 +211,8 @@ class VISIBILITY_HIDDEN TemplateRules : public ConstRules {
static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; }
static Constant *Xor (const ArgType *V1, const ArgType *V2) { return 0; }
static Constant *Shl (const ArgType *V1, const ArgType *V2) { return 0; }
- static Constant *Shr (const ArgType *V1, const ArgType *V2) { return 0; }
+ static Constant *LShr(const ArgType *V1, const ArgType *V2) { return 0; }
+ static Constant *AShr(const ArgType *V1, const ArgType *V2) { return 0; }
static Constant *LessThan(const ArgType *V1, const ArgType *V2) {
return 0;
}
@@ -420,12 +425,6 @@ struct VISIBILITY_HIDDEN ConstantPackedRules
static Constant *Xor(const ConstantPacked *V1, const ConstantPacked *V2) {
return EvalVectorOp(V1, V2, ConstantExpr::getXor);
}
- static Constant *Shl(const ConstantPacked *V1, const ConstantPacked *V2) {
- return EvalVectorOp(V1, V2, ConstantExpr::getShl);
- }
- static Constant *Shr(const ConstantPacked *V1, const ConstantPacked *V2) {
- return EvalVectorOp(V1, V2, ConstantExpr::getShr);
- }
static Constant *LessThan(const ConstantPacked *V1, const ConstantPacked *V2){
return 0;
}
@@ -581,9 +580,13 @@ struct VISIBILITY_HIDDEN DirectIntRules
return ConstantInt::get(*Ty, R);
}
- static Constant *Shr(const ConstantInt *V1, const ConstantInt *V2) {
- BuiltinType R =
- (BuiltinType)V1->getZExtValue() >> (BuiltinType)V2->getZExtValue();
+ static Constant *LShr(const ConstantInt *V1, const ConstantInt *V2) {
+ BuiltinType R = BuiltinType(V1->getZExtValue() >> V2->getZExtValue());
+ return ConstantInt::get(*Ty, R);
+ }
+
+ static Constant *AShr(const ConstantInt *V1, const ConstantInt *V2) {
+ BuiltinType R = BuiltinType(V1->getSExtValue() >> V2->getZExtValue());
return ConstantInt::get(*Ty, R);
}
};
@@ -1278,7 +1281,8 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
case Instruction::Or: C = ConstRules::get(V1, V2).op_or (V1, V2); break;
case Instruction::Xor: C = ConstRules::get(V1, V2).op_xor(V1, V2); break;
case Instruction::Shl: C = ConstRules::get(V1, V2).shl(V1, V2); break;
- case Instruction::Shr: C = ConstRules::get(V1, V2).shr(V1, V2); break;
+ case Instruction::LShr: C = ConstRules::get(V1, V2).lshr(V1, V2); break;
+ case Instruction::AShr: C = ConstRules::get(V1, V2).ashr(V1, V2); break;
case Instruction::SetEQ: C = ConstRules::get(V1, V2).equalto(V1, V2); break;
case Instruction::SetLT: C = ConstRules::get(V1, V2).lessthan(V1, V2);break;
case Instruction::SetGT: C = ConstRules::get(V1, V2).lessthan(V2, V1);break;
@@ -1366,21 +1370,20 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
return const_cast<Constant*>(V2); // X / undef -> undef
case Instruction::Or: // X | undef -> -1
return ConstantInt::getAllOnesValue(V1->getType());
- case Instruction::Shr:
- if (!isa<UndefValue>(V2)) {
- if (V1->getType()->isSigned())
- return const_cast<Constant*>(V1); // undef >>s X -> undef
- // undef >>u X -> 0
- } else if (isa<UndefValue>(V1)) {
- return const_cast<Constant*>(V1); // undef >> undef -> undef
- } else {
- if (V1->getType()->isSigned())
- return const_cast<Constant*>(V1); // X >>s undef -> X
- }
- return Constant::getNullValue(V1->getType());// X >>u undef -> 0
-
+ case Instruction::LShr:
+ if (isa<UndefValue>(V2) && isa<UndefValue>(V1))
+ return const_cast<Constant*>(V1); // undef lshr undef -> undef
+ return Constant::getNullValue(V1->getType()); // X lshr undef -> 0
+ // undef lshr X -> 0
+ case Instruction::AShr:
+ if (!isa<UndefValue>(V2))
+ return const_cast<Constant*>(V1); // undef ashr X --> undef
+ else if (isa<UndefValue>(V1))
+ return const_cast<Constant*>(V1); // undef ashr undef -> undef
+ else
+ return const_cast<Constant*>(V1); // X ashr undef --> X
case Instruction::Shl:
- // undef << X -> 0 X << undef -> 0
+ // undef << X -> 0 or X << undef -> 0
return Constant::getNullValue(V1->getType());
}
}
@@ -1466,7 +1469,8 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
return ConstantFoldBinaryInstruction(Opcode, V2, V1);
case Instruction::Shl:
- case Instruction::Shr:
+ case Instruction::LShr:
+ case Instruction::AShr:
case Instruction::Sub:
case Instruction::SDiv:
case Instruction::UDiv:
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index bcfd3879dbe..ee855ca7322 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -498,20 +498,11 @@ Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) {
Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
return get(Instruction::Shl, C1, C2);
}
-Constant *ConstantExpr::getShr(Constant *C1, Constant *C2) {
- return get(Instruction::Shr, C1, C2);
+Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2) {
+ return get(Instruction::LShr, C1, C2);
}
-
-Constant *ConstantExpr::getUShr(Constant *C1, Constant *C2) {
- if (C1->getType()->isUnsigned()) return getShr(C1, C2);
- return getCast(getShr(getCast(C1,
- C1->getType()->getUnsignedVersion()), C2), C1->getType());
-}
-
-Constant *ConstantExpr::getSShr(Constant *C1, Constant *C2) {
- if (C1->getType()->isSigned()) return getShr(C1, C2);
- return getCast(getShr(getCast(C1,
- C1->getType()->getSignedVersion()), C2), C1->getType());
+Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2) {
+ return get(Instruction::AShr, C1, C2);
}
/// getWithOperandReplaced - Return a constant expression identical to this
@@ -1330,7 +1321,9 @@ namespace llvm {
return new UnaryConstantExpr(Instruction::Cast, V.second[0], Ty);
if ((V.first >= Instruction::BinaryOpsBegin &&
V.first < Instruction::BinaryOpsEnd) ||
- V.first == Instruction::Shl || V.first == Instruction::Shr)
+ V.first == Instruction::Shl ||
+ V.first == Instruction::LShr ||
+ V.first == Instruction::AShr)
return new BinaryConstantExpr(V.first, V.second[0], V.second[1]);
if (V.first == Instruction::Select)
return new SelectConstantExpr(V.second[0], V.second[1], V.second[2]);
@@ -1364,7 +1357,8 @@ namespace llvm {
OldC->getOperand(2));
break;
case Instruction::Shl:
- case Instruction::Shr:
+ case Instruction::LShr:
+ case Instruction::AShr:
New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(),
OldC->getOperand(0), OldC->getOperand(1));
break;
@@ -1453,7 +1447,8 @@ Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) {
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
Constant *C1, Constant *C2) {
- if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)
+ 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 &&
@@ -1521,9 +1516,10 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
assert(C1->getType() == C2->getType() && "Op types should be identical!");
break;
case Instruction::Shl:
- case Instruction::Shr:
+ case Instruction::LShr:
+ case Instruction::AShr:
assert(C2->getType() == Type::UByteTy && "Shift should be by ubyte!");
- assert((C1->getType()->isInteger() || isa<PackedType>(C1->getType())) &&
+ assert(C1->getType()->isInteger() &&
"Tried to create a shift operation on a non-integer type!");
break;
default:
@@ -1558,8 +1554,9 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode,
Constant *C1, Constant *C2) {
// Check the operands for consistency first
- assert((Opcode == Instruction::Shl ||
- Opcode == Instruction::Shr) &&
+ assert((Opcode == Instruction::Shl ||
+ Opcode == Instruction::LShr ||
+ Opcode == Instruction::AShr) &&
"Invalid opcode in binary constant expression");
assert(C1->getType()->isIntegral() && C2->getType() == Type::UByteTy &&
"Invalid operand types for Shift constant expr!");
diff --git a/llvm/lib/VMCore/Instruction.cpp b/llvm/lib/VMCore/Instruction.cpp
index 355c508b6a6..70b375902dc 100644
--- a/llvm/lib/VMCore/Instruction.cpp
+++ b/llvm/lib/VMCore/Instruction.cpp
@@ -128,7 +128,8 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
case Select: return "select";
case Call: return "call";
case Shl: return "shl";
- case Shr: return "shr";
+ case LShr: return "lshr";
+ case AShr: return "ashr";
case VAArg: return "va_arg";
case ExtractElement: return "extractelement";
case InsertElement: return "insertelement";
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 3825d857634..5ed07cfb7f7 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -1222,17 +1222,6 @@ bool BinaryOperator::swapOperands() {
return false;
}
-
-//===----------------------------------------------------------------------===//
-// ShiftInst Class
-//===----------------------------------------------------------------------===//
-
-/// isLogicalShift - Return true if this is a logical shift left or a logical
-/// shift right.
-bool ShiftInst::isLogicalShift() const {
- return getOpcode() == Instruction::Shl || getType()->isUnsigned();
-}
-
//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud