summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pop <spop@codeaurora.org>2012-10-18 19:53:48 +0000
committerSebastian Pop <spop@codeaurora.org>2012-10-18 19:53:48 +0000
commit83ba06afa8503dc97a0aa5ec033022286959956c (patch)
treed926199c8b34ac68b1e2a33c922eb2214a3e9796
parentbf0683f0f75dfb92e73b09718ed278eeab8ba9d2 (diff)
Clear unknown mem ops when merging stack slots (pr14090)
When merging stack slots, if StackColoring::remapInstructions gets a value back from GetUnderlyingObject that it does not know about or is not itself a stack slot, clear the memory operand in case it aliases the merged slot. This prevents the introduction of incorrect aliasing information. Author: Matthew Curtis <mcurtis@codeaurora.org> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166216 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/StackColoring.cpp19
-rw-r--r--test/CodeGen/X86/pr14090.ll76
2 files changed, 89 insertions, 6 deletions
diff --git a/lib/CodeGen/StackColoring.cpp b/lib/CodeGen/StackColoring.cpp
index 3150f3dfaa8..1cbee843a12 100644
--- a/lib/CodeGen/StackColoring.cpp
+++ b/lib/CodeGen/StackColoring.cpp
@@ -261,7 +261,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
MarkersFound++;
- const Value *Allocation = MFI->getObjectAllocation(Slot);
+ const AllocaInst *Allocation = MFI->getObjectAllocation(Slot);
if (Allocation) {
DEBUG(dbgs()<<"Found a lifetime marker for slot #"<<Slot<<
" with allocation: "<< Allocation->getName()<<"\n");
@@ -481,11 +481,11 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
}
// Keep a list of *allocas* which need to be remapped.
- DenseMap<const Value*, const Value*> Allocas;
+ DenseMap<const AllocaInst*, const AllocaInst*> Allocas;
for (DenseMap<int, int>::iterator it = SlotRemap.begin(),
e = SlotRemap.end(); it != e; ++it) {
- const Value *From = MFI->getObjectAllocation(it->first);
- const Value *To = MFI->getObjectAllocation(it->second);
+ const AllocaInst *From = MFI->getObjectAllocation(it->first);
+ const AllocaInst *To = MFI->getObjectAllocation(it->second);
assert(To && From && "Invalid allocation object");
Allocas[From] = To;
}
@@ -515,10 +515,17 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
V = GetUnderlyingObject(V);
// If we did not find one, or if the one that we found is not in our
// map, then move on.
- if (!V || !Allocas.count(V))
+ if (!V || !isa<AllocaInst>(V)) {
+ // Clear mem operand since we don't know for sure that it doesn't
+ // alias a merged alloca.
+ MMO->setValue(0);
+ continue;
+ }
+ const AllocaInst *AI= cast<AllocaInst>(V);
+ if (!Allocas.count(AI))
continue;
- MMO->setValue(Allocas[V]);
+ MMO->setValue(Allocas[AI]);
FixedMemOp++;
}
diff --git a/test/CodeGen/X86/pr14090.ll b/test/CodeGen/X86/pr14090.ll
new file mode 100644
index 00000000000..d76b912fd8e
--- /dev/null
+++ b/test/CodeGen/X86/pr14090.ll
@@ -0,0 +1,76 @@
+; RUN: llc < %s -march=x86-64 -print-before=stack-coloring -print-after=stack-coloring >%t 2>&1 && FileCheck <%t %s
+
+define void @foo(i64* %retval.i, i32 %call, i32* %.ph.i80, i32 %fourteen, i32* %out.lo, i32* %out.hi) nounwind align 2 {
+entry:
+ %_Tmp.i39 = alloca i64, align 8
+ %retval.i33 = alloca i64, align 8
+ %_Tmp.i = alloca i64, align 8
+ %retval.i.i = alloca i64, align 8
+ %_First.i = alloca i64, align 8
+
+ %0 = load i64* %retval.i, align 8
+
+ %1 = load i64* %retval.i, align 8
+
+ %_Tmp.i39.0.cast73 = bitcast i64* %_Tmp.i39 to i8*
+ call void @llvm.lifetime.start(i64 8, i8* %_Tmp.i39.0.cast73)
+ store i64 %1, i64* %_Tmp.i39, align 8
+ %cmp.i.i.i40 = icmp slt i32 %call, 0
+ %2 = lshr i64 %1, 32
+ %3 = trunc i64 %2 to i32
+ %sub.i.i.i44 = sub i32 0, %call
+ %cmp2.i.i.i45 = icmp ult i32 %3, %sub.i.i.i44
+ %or.cond.i.i.i46 = and i1 %cmp.i.i.i40, %cmp2.i.i.i45
+ %add.i.i.i47 = add i32 %3, %call
+ %sub5.i.i.i48 = lshr i32 %add.i.i.i47, 5
+ %trunc.i50 = trunc i64 %1 to i32
+ %inttoptr.i51 = inttoptr i32 %trunc.i50 to i32*
+ %add61617.i.i.i52 = or i32 %sub5.i.i.i48, -134217728
+ %add61617.i.sub5.i.i.i53 = select i1 %or.cond.i.i.i46, i32 %add61617.i.i.i52, i32 %sub5.i.i.i48
+ %storemerge2.i.i54 = getelementptr inbounds i32* %inttoptr.i51, i32 %add61617.i.sub5.i.i.i53
+ %_Tmp.i39.0.cast74 = bitcast i64* %_Tmp.i39 to i32**
+ store i32* %storemerge2.i.i54, i32** %_Tmp.i39.0.cast74, align 8
+ %storemerge.i.i55 = and i32 %add.i.i.i47, 31
+ %_Tmp.i39.4.raw_idx = getelementptr inbounds i8* %_Tmp.i39.0.cast73, i32 4
+ %_Tmp.i39.4.cast = bitcast i8* %_Tmp.i39.4.raw_idx to i32*
+ store i32 %storemerge.i.i55, i32* %_Tmp.i39.4.cast, align 4
+ %srcval.i56 = load i64* %_Tmp.i39, align 8
+ call void @llvm.lifetime.end(i64 8, i8* %_Tmp.i39.0.cast73)
+
+; CHECK: Before Merge disjoint stack slots
+; CHECK: [[PREFIX15:MOV64mr.*<fi#]]{{[0-9]}}[[SUFFIX15:.*;]] mem:ST8[%fifteen]
+; CHECK: [[PREFIX87:MOV32mr.*;]] mem:ST4[%sunkaddr87]
+
+; CHECK: After Merge disjoint stack slots
+; CHECK: [[PREFIX15]]{{[0-9]}}[[SUFFIX15]] mem:ST8[%_Tmp.i39]
+; CHECK: [[PREFIX87]] mem:ST4[<unknown>]
+
+ %fifteen = bitcast i64* %retval.i.i to i32**
+ %sixteen = bitcast i64* %retval.i.i to i8*
+ call void @llvm.lifetime.start(i64 8, i8* %sixteen)
+ store i32* %.ph.i80, i32** %fifteen, align 8, !tbaa !0
+ %sunkaddr = ptrtoint i64* %retval.i.i to i32
+ %sunkaddr86 = add i32 %sunkaddr, 4
+ %sunkaddr87 = inttoptr i32 %sunkaddr86 to i32*
+ store i32 %fourteen, i32* %sunkaddr87, align 4, !tbaa !3
+ %seventeen = load i64* %retval.i.i, align 8
+ call void @llvm.lifetime.end(i64 8, i8* %sixteen)
+ %eighteen = lshr i64 %seventeen, 32
+ %nineteen = trunc i64 %eighteen to i32
+ %shl.i.i.i = shl i32 1, %nineteen
+
+ store i32 %shl.i.i.i, i32* %out.lo, align 8
+ store i32 %nineteen, i32* %out.hi, align 8
+
+ ret void
+}
+
+declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
+
+declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
+
+!0 = metadata !{metadata !"int", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA"}
+!3 = metadata !{metadata !"any pointer", metadata !1}
+!4 = metadata !{metadata !"vtable pointer", metadata !2}