summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-19 19:56:44 +0000
committerChris Lattner <sabre@nondot.org>2011-02-19 19:56:44 +0000
commit72a35fb97457c2b26c77322f24d2f129959bc7e5 (patch)
tree2b4b95e5053de8f03cd4e02ff5b0ea871141ba17 /llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
parentacf6b0776a624f1ef0400b131d1623cae24b3409 (diff)
downloadbcm5719-llvm-72a35fb97457c2b26c77322f24d2f129959bc7e5.tar.gz
bcm5719-llvm-72a35fb97457c2b26c77322f24d2f129959bc7e5.zip
rewrite the memset_pattern pattern generation stuff to accept any 2/4/8/16-byte
constant, including globals. This makes us generate much more "pretty" pattern globals as well because it doesn't break it down to an array of bytes all the time. This enables us to handle stores of relocatable globals. This kicks in about 48 times in 254.gap, giving us stuff like this: @.memset_pattern40 = internal constant [2 x %struct.TypHeader* (%struct.TypHeader*, %struct.TypHeader*)*] [%struct.TypHeader* (%struct.TypHeader*, %struct .TypHeader*)* @IsFalse, %struct.TypHeader* (%struct.TypHeader*, %struct.TypHeader*)* @IsFalse], align 16 ... call void @memset_pattern16(i8* %scevgep5859, i8* bitcast ([2 x %struct.TypHeader* (%struct.TypHeader*, %struct.TypHeader*)*]* @.memset_pattern40 to i8* ), i64 %tmp75) nounwind llvm-svn: 126044
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp44
1 files changed, 12 insertions, 32 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index be3ff9258fc..d7fa149492b 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -388,43 +388,24 @@ static Constant *getMemSetPatternValue(Value *V, const TargetData &TD) {
if (Size == 0 || (Size & 7) || (Size & (Size-1)))
return 0;
- // Convert the constant to an integer type of the appropriate size so we can
- // start hacking on it.
- if (isa<PointerType>(V->getType()))
- C = ConstantExpr::getPtrToInt(C, IntegerType::get(C->getContext(), Size));
- else if (isa<VectorType>(V->getType()) || V->getType()->isFloatingPointTy())
- C = ConstantExpr::getBitCast(C, IntegerType::get(C->getContext(), Size));
- else if (!isa<IntegerType>(V->getType()))
- return 0; // Unhandled type.
+ // Don't care enough about darwin/ppc to implement this.
+ if (TD.isBigEndian())
+ return 0;
// Convert to size in bytes.
Size /= 8;
-
- // If we couldn't fold this to an integer, we fail. We don't bother to handle
- // relocatable expressions like the address of a global yet.
- // FIXME!
- ConstantInt *CI = dyn_cast<ConstantInt>(C);
- if (CI == 0) return 0;
- APInt CVal = CI->getValue();
-
// TODO: If CI is larger than 16-bytes, we can try slicing it in half to see
- // if the top and bottom are the same.
+ // if the top and bottom are the same (e.g. for vectors and large integers).
if (Size > 16) return 0;
-
- // If this is a big endian target (PPC) then we need to bswap.
- if (TD.isBigEndian())
- CVal = CVal.byteSwap();
-
- // Determine what each byte of the pattern value should be.
- char Value[16];
- for (unsigned i = 0; i != 16; ++i) {
- // Get the byte value we're indexing into.
- unsigned CByte = i % Size;
- Value[i] = (unsigned char)(CVal.getZExtValue() >> CByte);
- }
- return ConstantArray::get(V->getContext(), StringRef(Value, 16), false);
+ // If the constant is exactly 16 bytes, just use it.
+ if (Size == 16) return C;
+
+ // Otherwise, we'll use an array of the constants.
+ unsigned ArraySize = 16/Size;
+ ArrayType *AT = ArrayType::get(V->getType(), ArraySize);
+ return ConstantArray::get(AT, std::vector<Constant*>(ArraySize, C));
}
@@ -518,8 +499,7 @@ processLoopStridedStore(Value *DestPtr, unsigned StoreSize,
PatternValue, ".memset_pattern");
GV->setUnnamedAddr(true); // Ok to merge these.
GV->setAlignment(16);
- Value *PatternPtr = Builder.CreateConstInBoundsGEP2_32(GV, 0, 0, "pattern");
-
+ Value *PatternPtr = ConstantExpr::getBitCast(GV, Builder.getInt8PtrTy());
NewCall = Builder.CreateCall3(MSP, BasePtr, PatternPtr, NumBytes);
}
OpenPOWER on IntegriCloud