aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-01 20:57:36 +0000
committerChris Lattner <sabre@nondot.org>2007-04-01 20:57:36 +0000
commit55fc8c4c39005424f72968e8a3e9355d9611945c (patch)
tree967fa5005a012849f06a274ed87e9abb7f0f8af2
parent3e9f1d09c0dc7c3921ebd32d9be45d1fdf182bf2 (diff)
downloadexternal_llvm-55fc8c4c39005424f72968e8a3e9355d9611945c.zip
external_llvm-55fc8c4c39005424f72968e8a3e9355d9611945c.tar.gz
external_llvm-55fc8c4c39005424f72968e8a3e9355d9611945c.tar.bz2
simplify this code, make it work for ap ints
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35561 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index b3679a9..87f9667 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3594,14 +3594,14 @@ static bool CollectBSwapParts(Value *V, SmallVector<Value*, 8> &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 cannot bswap one byte.
- if (I.getType() == Type::Int8Ty)
- return 0;
+ const IntegerType *ITy = dyn_cast<IntegerType>(I.getType());
+ if (!ITy || ITy->getBitWidth() % 16)
+ return 0; // Can only bswap pairs of bytes. Can't do vectors.
/// ByteValues - For each byte of the result, we keep track of which value
/// defines each byte.
SmallVector<Value*, 8> ByteValues;
- ByteValues.resize(TD->getTypeSize(I.getType()));
+ ByteValues.resize(ITy->getBitWidth()/8);
// Try to find all the pieces corresponding to the bswap.
if (CollectBSwapParts(I.getOperand(0), ByteValues) ||
@@ -3616,20 +3616,9 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) {
for (unsigned i = 1, e = ByteValues.size(); i != e; ++i)
if (ByteValues[i] != V)
return 0;
-
- // If they do then *success* we can turn this into a bswap. Figure out what
- // bswap to make it into.
+ const Type *Tys[] = { ITy, ITy };
Module *M = I.getParent()->getParent()->getParent();
- const char *FnName = 0;
- if (I.getType() == Type::Int16Ty)
- FnName = "llvm.bswap.i16.i16";
- else if (I.getType() == Type::Int32Ty)
- FnName = "llvm.bswap.i32.i32";
- else if (I.getType() == Type::Int64Ty)
- FnName = "llvm.bswap.i64.i64";
- else
- assert(0 && "Unknown integer type!");
- Constant *F = M->getOrInsertFunction(FnName, I.getType(), I.getType(), NULL);
+ Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 2);
return new CallInst(F, V);
}