llvm.org GIT mirror llvm / 80e8b50
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126044 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
2 changed file(s) with 41 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
387387 if (Size == 0 || (Size & 7) || (Size & (Size-1)))
388388 return 0;
389389
390 // Convert the constant to an integer type of the appropriate size so we can
391 // start hacking on it.
392 if (isa(V->getType()))
393 C = ConstantExpr::getPtrToInt(C, IntegerType::get(C->getContext(), Size));
394 else if (isa(V->getType()) || V->getType()->isFloatingPointTy())
395 C = ConstantExpr::getBitCast(C, IntegerType::get(C->getContext(), Size));
396 else if (!isa(V->getType()))
397 return 0; // Unhandled type.
390 // Don't care enough about darwin/ppc to implement this.
391 if (TD.isBigEndian())
392 return 0;
398393
399394 // Convert to size in bytes.
400395 Size /= 8;
401
402 // If we couldn't fold this to an integer, we fail. We don't bother to handle
403 // relocatable expressions like the address of a global yet.
404 // FIXME!
405 ConstantInt *CI = dyn_cast(C);
406 if (CI == 0) return 0;
407
408 APInt CVal = CI->getValue();
409
396
410397 // TODO: If CI is larger than 16-bytes, we can try slicing it in half to see
411 // if the top and bottom are the same.
398 // if the top and bottom are the same (e.g. for vectors and large integers).
412399 if (Size > 16) return 0;
413
414 // If this is a big endian target (PPC) then we need to bswap.
415 if (TD.isBigEndian())
416 CVal = CVal.byteSwap();
417
418 // Determine what each byte of the pattern value should be.
419 char Value[16];
420 for (unsigned i = 0; i != 16; ++i) {
421 // Get the byte value we're indexing into.
422 unsigned CByte = i % Size;
423 Value[i] = (unsigned char)(CVal.getZExtValue() >> CByte);
424 }
425
426 return ConstantArray::get(V->getContext(), StringRef(Value, 16), false);
400
401 // If the constant is exactly 16 bytes, just use it.
402 if (Size == 16) return C;
403
404 // Otherwise, we'll use an array of the constants.
405 unsigned ArraySize = 16/Size;
406 ArrayType *AT = ArrayType::get(V->getType(), ArraySize);
407 return ConstantArray::get(AT, std::vector(ArraySize, C));
427408 }
428409
429410
517498 PatternValue, ".memset_pattern");
518499 GV->setUnnamedAddr(true); // Ok to merge these.
519500 GV->setAlignment(16);
520 Value *PatternPtr = Builder.CreateConstInBoundsGEP2_32(GV, 0, 0, "pattern");
521
501 Value *PatternPtr = ConstantExpr::getBitCast(GV, Builder.getInt8PtrTy());
522502 NewCall = Builder.CreateCall3(MSP, BasePtr, PatternPtr, NumBytes);
523503 }
524504
276276 ; On darwin10 (which is the triple in this .ll file) this loop can be turned
277277 ; into a memset_pattern call.
278278 ; rdar://9009151
279 define void @test11(i32* nocapture %P) nounwind ssp {
279 define void @test11_pattern(i32* nocapture %P) nounwind ssp {
280280 entry:
281281 br label %for.body
282282
290290
291291 for.end: ; preds = %for.body
292292 ret void
293 ; CHECK: @test11
293 ; CHECK: @test11_pattern
294294 ; CHECK-NEXT: entry:
295295 ; CHECK-NEXT: bitcast
296296 ; CHECK-NEXT: memset_pattern
321321 ; CHECK: ret void
322322 }
323323
324 @G = global i32 5
325
326 ; This store-of-address loop can be turned into a memset_pattern call.
327 ; rdar://9009151
328 define void @test13_pattern(i32** nocapture %P) nounwind ssp {
329 entry:
330 br label %for.body
331
332 for.body: ; preds = %entry, %for.body
333 %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
334 %arrayidx = getelementptr i32** %P, i64 %indvar
335 store i32* @G, i32** %arrayidx, align 4
336 %indvar.next = add i64 %indvar, 1
337 %exitcond = icmp eq i64 %indvar.next, 10000
338 br i1 %exitcond, label %for.end, label %for.body
339
340 for.end: ; preds = %for.body
341 ret void
342 ; CHECK: @test13_pattern
343 ; CHECK-NEXT: entry:
344 ; CHECK-NEXT: bitcast
345 ; CHECK-NEXT: memset_pattern
346 ; CHECK-NOT: store
347 ; CHECK: ret void
348 }