[PATCH] D75173: [Transform][MemCpyOpt] Add missing DebugLoc to %tmpbitcast
Pierre van Houtryve via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 02:08:54 PST 2020
Pierre-vh updated this revision to Diff 247188.
Pierre-vh added a comment.
Hello,
- I made the test as small as I could
- I added 2 run lines, one checks for the correctness of the LLVM IR, the other checks that debugify passes
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75173/new/
https://reviews.llvm.org/D75173
Files:
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/pr37967.ll
Index: llvm/test/Transforms/MemCpyOpt/pr37967.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/MemCpyOpt/pr37967.ll
@@ -0,0 +1,26 @@
+; RUN: opt -instcombine -memcpyopt -debugify -S < %s 2>&1 | FileCheck %s
+; RUN: opt -debugify-each -disable-output -instcombine -memcpyopt < %s 2>&1 | FileCheck %s --check-prefix=DEBUGIFY
+
+; CHECK-LABEL: define {{.*}} @_Z3bar3Foo
+; CHECK: [[target:%.*]] = load i8*, i8** bitcast (%struct.Foo** @a to i8**), align 8, !dbg
+; CHECK: %tmpcast = bitcast i8* [[target]] to %struct.Foo*, !dbg
+
+; DEBUGIFY: CheckFunctionDebugify [MemCpy Optimization]: PASS
+
+%struct.Foo = type { i64, i64, i64 }
+
+ at a = dso_local global %struct.Foo* null, align 8
+
+define dso_local void @_Z3bar3Foo(%struct.Foo* byval(%struct.Foo) align 8 %0) {
+entry:
+ %agg.tmp = alloca %struct.Foo, align 8
+ %1 = load %struct.Foo*, %struct.Foo** @a, align 8
+ %arrayidx = getelementptr inbounds %struct.Foo, %struct.Foo* %1, i64 0
+ %2 = bitcast %struct.Foo* %agg.tmp to i8*
+ %3 = bitcast %struct.Foo* %arrayidx to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %2, i8* align 8 %3, i64 24, i1 false)
+ call void @_Z3bar3Foo(%struct.Foo* byval(%struct.Foo) align 8 %agg.tmp)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1302,9 +1302,13 @@
return false;
Value *TmpCast = MDep->getSource();
- if (MDep->getSource()->getType() != ByValArg->getType())
- TmpCast = new BitCastInst(MDep->getSource(), ByValArg->getType(),
- "tmpcast", CS.getInstruction());
+ if (MDep->getSource()->getType() != ByValArg->getType()) {
+ BitCastInst *TmpBitCast = new BitCastInst(MDep->getSource(), ByValArg->getType(),
+ "tmpcast", CS.getInstruction());
+ // Set the tmpcast's DebugLoc to MDep's
+ TmpBitCast->setDebugLoc(MDep->getDebugLoc());
+ TmpCast = TmpBitCast;
+ }
LLVM_DEBUG(dbgs() << "MemCpyOptPass: Forwarding memcpy to byval:\n"
<< " " << *MDep << "\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75173.247188.patch
Type: text/x-patch
Size: 2377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200228/17fa4f44/attachment.bin>
More information about the llvm-commits
mailing list