<div dir="ltr">Hi,<div><br></div><div>Looking further at this, the issue stems from the type involved, which is x86_fp80. This type has a n AllocSize of 128 bits but an "actual" size of 80 bits. Part of SROA is using the alloc size and another part is using the non-alloc size which is why we get a size disparity.</div><div><br></div><div>I've put assertions in to this code that fire when DL.getTypeSizeInBits != DL.getTypeAllocSizeInBits, and those never fire in the test suite. </div><div><br></div><div>As this patch isn't sufficiently tested, I vote that we revert this patch.</div><div><br></div><div>Thoughts?</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div><br><div class="gmail_quote"><div dir="ltr">On Mon, 15 Aug 2016 at 10:52 James Molloy <<a href="mailto:james@jamesmolloy.co.uk">james@jamesmolloy.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>Hi Keno, Adrian,<div><br></div><div>A recent change of mine to SimplifyCFG exposed a bug in this commit. This assert is firing:</div><div><br></div><div><div>       assert(Pieces.size() == 1 &&</div></div></div><div dir="ltr"><div><div>               "partition is as large as original alloca");</div></div></div><div dir="ltr"><div></div><div><br></div><div>From the phab review it looks like this assert was added in late in the review process and my testing shows that this assert is never tested at all in the regression tests (changing to assert(0) doesn't cause any failures!)</div><div><br></div><div>The error is shown here: <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/23920/steps/annotate/logs/stdio" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/23920/steps/annotate/logs/stdio</a></div><div><br></div><div>It's easily reproducible with ToT clang simply compiling the file projects/compiler-rt/lib/builtins/powixf2.c *with debug info enabled (-g)*.</div><div><br></div><div>I'd fix it myself but after staring for a while I can't work out if the the assert sense is wrong (the text "partition is as large as original alloca" seems like a failure mode to me, which would indicate that perhaps the test should have been "Pieces.size() != 1" ?) or if the assert is correct but there is a failure somewhere else.</div><div><br></div><div>Could you please take a look?</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><div dir="ltr"><div><br><div class="gmail_quote"><div dir="ltr">On Thu, 14 Jan 2016 at 20:10 Keno Fischer via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kfischer<br>
Date: Thu Jan 14 14:06:34 2016<br>
New Revision: 257795<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=257795&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=257795&view=rev</a><br>
Log:<br>
[SROA] Also insert a bit piece expression if only one piece is needed<br>
<br>
Summary: If SROA creates only one piece (e.g. because the other is not needed),<br>
it still needs to create a bit_piece expression if that bit piece is smaller<br>
than the original size of the alloca.<br>
<br>
Reviewers: aprantl<br>
<br>
Subscribers: llvm-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D16187" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16187</a><br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=257795&r1=257794&r2=257795&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=257795&r1=257794&r2=257795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Thu Jan 14 14:06:34 2016<br>
@@ -4024,12 +4024,12 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
     auto *Var = DbgDecl->getVariable();<br>
     auto *Expr = DbgDecl->getExpression();<br>
     DIBuilder DIB(*AI.getModule(), /*AllowUnresolved*/ false);<br>
-    bool IsSplit = Pieces.size() > 1;<br>
+    uint64_t AllocaSize = DL.getTypeSizeInBits(AI.getAllocatedType());<br>
     for (auto Piece : Pieces) {<br>
       // Create a piece expression describing the new partition or reuse AI's<br>
       // expression if there is only one partition.<br>
       auto *PieceExpr = Expr;<br>
-      if (IsSplit || Expr->isBitPiece()) {<br>
+      if (Piece.Size < AllocaSize || Expr->isBitPiece()) {<br>
         // If this alloca is already a scalar replacement of a larger aggregate,<br>
         // Piece.Offset describes the offset inside the scalar.<br>
         uint64_t Offset = Expr->isBitPiece() ? Expr->getBitPieceOffset() : 0;<br>
@@ -4043,6 +4043,9 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
           Size = std::min(Size, AbsEnd - Start);<br>
         }<br>
         PieceExpr = DIB.createBitPieceExpression(Start, Size);<br>
+      } else {<br>
+        assert(Pieces.size() == 1 &&<br>
+               "partition is as large as original alloca");<br>
       }<br>
<br>
       // Remove any existing dbg.declare intrinsic describing the same alloca.<br>
<br>
Added: llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll?rev=257795&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll?rev=257795&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll (added)<br>
+++ llvm/trunk/test/Transforms/SROA/dbg-single-piece.ll Thu Jan 14 14:06:34 2016<br>
@@ -0,0 +1,37 @@<br>
+; RUN: opt -sroa %s -S | FileCheck %s<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
+<br>
+%foo = type { [8 x i8], [8 x i8] }<br>
+<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0<br>
+define void @_ZL18findInsertLocationPN4llvm17MachineBasicBlockENS_9SlotIndexERNS_13LiveIntervalsE() {<br>
+entry:<br>
+  %retval = alloca %foo, align 8<br>
+  call void @llvm.dbg.declare(metadata %foo* %retval, metadata !1, metadata !7), !dbg !8<br>
+; Checks that SROA still inserts a bit_piece expression, even if it produces only one piece<br>
+; (as long as that piece is smaller than the whole thing)<br>
+; CHECK-NOT: call void @llvm.dbg.value<br>
+; CHECK: call void @llvm.dbg.value(metadata %foo* undef, i64 0, metadata !1, metadata ![[BIT_PIECE:[0-9]+]]), !dbg<br>
+; CHECK-NOT: call void @llvm.dbg.value<br>
+; CHECK: ![[BIT_PIECE]] = !DIExpression(DW_OP_bit_piece, 64, 64)<br>
+  %0 = bitcast %foo* %retval to i8*<br>
+  %1 = getelementptr inbounds i8, i8* %0, i64 8<br>
+  %2 = bitcast i8* %1 to %foo**<br>
+  store %foo* undef, %foo** %2, align 8<br>
+  ret void<br>
+}<br>
+<br>
+attributes #0 = { nounwind readnone }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{}<br>
+!llvm.module.flags = !{!0}<br>
+<br>
+!0 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!1 = !DILocalVariable(name: "I", scope: !2, file: !3, line: 947, type: !4)<br>
+!2 = distinct !DISubprogram(name: "findInsertLocation", linkageName: "_ZL18findInsertLocationPN4llvm17MachineBasicBlockENS_9SlotIndexERNS_13LiveIntervalsE", scope: !3, file: !3, line: 937, isLocal: true, isDefinition: true, scopeLine: 938, flags: DIFlagPrototyped, isOptimized: true)<br>
+!3 = !DIFile(filename: "none", directory: ".")<br>
+!4 = !DICompositeType(tag: DW_TAG_class_type, name: "bundle_iterator<llvm::MachineInstr, llvm::ilist_iterator<llvm::MachineInstr> >", scope: !5, file: !3, line: 163, size: 128, align: 64, elements: !6, templateParams: !6, identifier: "_ZTSN4llvm17MachineBasicBlock15bundle_iteratorINS_12MachineInstrENS_14ilist_iteratorIS2_EEEE")<br>
+!5 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "MachineBasicBlock", file: !3, line: 68, size: 1408, align: 64, identifier: "_ZTSN4llvm17MachineBasicBlockE")<br>
+!6 = !{}<br>
+!7 = !DIExpression()<br>
+!8 = !DILocation(line: 947, column: 35, scope: !2)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></blockquote></div></div>