mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-13 14:46:53 +00:00
[MemCpyOpt] Do move the memset, but look at its dest's dependencies.
In effect a partial revert of r237858, which was a dumb shortcut. Looking at the dependencies of the destination should be the proper fix: if the new memset would depend on anything other than itself, the transformation isn't correct. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237874 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4652459f64
commit
8eca988b00
@ -859,6 +859,13 @@ bool MemCpyOpt::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
|
||||
if (MemSet->getDest() != MemCpy->getDest())
|
||||
return false;
|
||||
|
||||
// Check that there are no other dependencies on the memset destination.
|
||||
MemDepResult DstDepInfo =
|
||||
MD->getPointerDependencyFrom(AliasAnalysis::getLocationForDest(MemSet),
|
||||
false, MemCpy, MemCpy->getParent());
|
||||
if (DstDepInfo.getInst() != MemSet)
|
||||
return false;
|
||||
|
||||
// Use the same i8* dest as the memcpy, killing the memset dest if different.
|
||||
Value *Dest = MemCpy->getRawDest();
|
||||
Value *DestSize = MemSet->getLength();
|
||||
@ -874,7 +881,7 @@ bool MemCpyOpt::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
|
||||
if (ConstantInt *SrcSizeC = dyn_cast<ConstantInt>(SrcSize))
|
||||
Align = MinAlign(SrcSizeC->getZExtValue(), DestAlign);
|
||||
|
||||
IRBuilder<> Builder(MemSet);
|
||||
IRBuilder<> Builder(MemCpy);
|
||||
|
||||
// If the sizes have different types, zext the smaller one.
|
||||
if (DestSize->getType() != SrcSize->getType()) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
; RUN: opt -memcpyopt -S %s | FileCheck %s
|
||||
; RUN: opt -basicaa -memcpyopt -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
@ -140,6 +140,26 @@ define i8 @test_intermediate_read(i8* %a, i8* %b) #0 {
|
||||
ret i8 %r
|
||||
}
|
||||
|
||||
%struct = type { [8 x i8], [8 x i8] }
|
||||
|
||||
; CHECK-LABEL: define void @test_intermediate_write
|
||||
; CHECK-NEXT: %a = alloca %struct
|
||||
; CHECK-NEXT: %a0 = getelementptr %struct, %struct* %a, i32 0, i32 0, i32 0
|
||||
; CHECK-NEXT: %a1 = getelementptr %struct, %struct* %a, i32 0, i32 1, i32 0
|
||||
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %a0, i8 0, i64 16, i32 1, i1 false)
|
||||
; CHECK-NEXT: store i8 1, i8* %a1
|
||||
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a0, i8* %b, i64 8, i32 1, i1 false)
|
||||
; CHECK-NEXT: ret void
|
||||
define void @test_intermediate_write(i8* %b) #0 {
|
||||
%a = alloca %struct
|
||||
%a0 = getelementptr %struct, %struct* %a, i32 0, i32 0, i32 0
|
||||
%a1 = getelementptr %struct, %struct* %a, i32 0, i32 1, i32 0
|
||||
call void @llvm.memset.p0i8.i64(i8* %a0, i8 0, i64 16, i32 1, i1 false)
|
||||
store i8 1, i8* %a1
|
||||
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a0, i8* %b, i64 8, i32 1, i1 false)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1)
|
||||
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
|
||||
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1)
|
||||
|
Loading…
Reference in New Issue
Block a user