<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sanitizers introduce instrumentation (IIRC) so things are not quite as pristine as the debug-info mandate to have no effect on code generation. But this is
the kind of thing I did years ago on a different compiler, to improve debug-info quality at –O1.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">That is: I think this kind of optimization de-tuning is more broadly useful than just for the sanitizers and it’s worth having a discussion around it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvm-commits-bounces@cs.uiuc.edu [mailto:llvm-commits-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>David Blaikie<br>
<b>Sent:</b> Monday, November 18, 2013 1:27 PM<br>
<b>To:</b> reviews+D2214+public+18620cda62016bc9@llvm-reviews.chandlerc.com<br>
<b>Cc:</b> llvm-commits@cs.uiuc.edu; eugenis@google.com<br>
<b>Subject:</b> Re: [PATCH] Disable branch folding with MemorySanitizer<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Do we have precedence for this kind of change (where sanitizers affect optimizations in arbitrary internal ways - not simply by enabling/disabling certain passes)? If not, does this need some deeper discussion about alternatives (is it
important that we be able to produce equivalent code without the sanitizers enabled?)?<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Nov 18, 2013 at 7:02 AM, Evgeniy Stepanov <<a href="mailto:eugenis@google.com" target="_blank">eugenis@google.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Branch folding optimization often leads to confusing MSan reports due to lost debug info.<br>
For example,<br>
1: if (x < 0)<br>
2: if (y < 0)<br>
3: do_something();<br>
is transformed into something like<br>
%0 = and i32 %y, %x<br>
%1 = icmp slt i32 %0, 0<br>
br i1 %1, label %if.then2, label %if.end3<br>
where all 3 instructions are associated with line 1.<br>
<br>
This patch disables folding of conditional branches in functions with sanitize_memory attribute.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D2214" target="_blank">http://llvm-reviews.chandlerc.com/D2214</a><br>
<br>
Files:<br>
lib/Transforms/Utils/SimplifyCFG.cpp<br>
test/Transforms/SimplifyCFG/branch-fold-msan.ll<br>
<br>
Index: lib/Transforms/Utils/SimplifyCFG.cpp<br>
===================================================================<br>
--- lib/Transforms/Utils/SimplifyCFG.cpp<br>
+++ lib/Transforms/Utils/SimplifyCFG.cpp<br>
@@ -1967,6 +1967,13 @@<br>
bool llvm::FoldBranchToCommonDest(BranchInst *BI) {<br>
BasicBlock *BB = BI->getParent();<br>
<br>
+ // This optimization results in confusing MemorySanitizer reports. Use of<br>
+ // uninitialized value in this branch instruction is reported with the<br>
+ // predecessor's debug location.<br>
+ if (BB->getParent()->hasFnAttribute(Attribute::SanitizeMemory) &&<br>
+ BI->isConditional())<br>
+ return false;<br>
+<br>
Instruction *Cond = 0;<br>
if (BI->isConditional())<br>
Cond = dyn_cast<Instruction>(BI->getCondition());<br>
Index: test/Transforms/SimplifyCFG/branch-fold-msan.ll<br>
===================================================================<br>
--- test/Transforms/SimplifyCFG/branch-fold-msan.ll<br>
+++ test/Transforms/SimplifyCFG/branch-fold-msan.ll<br>
@@ -0,0 +1,29 @@<br>
+; RUN: opt < %s -simplifycfg -S | FileCheck %s<br>
+<br>
+declare void @callee()<br>
+<br>
+; Test that conditional branches are not folded with sanitize_memory.<br>
+define void @caller(i32 %x, i32 %y) sanitize_memory {<br>
+; CHECK: define void @caller(i32 [[X:%.*]], i32 [[Y:%.*]])<br>
+; CHECK: icmp slt i32 {{.*}}[[X]]<br>
+; CHECK: icmp slt i32 {{.*}}[[Y]]<br>
+; CHECK: ret void<br>
+<br>
+entry:<br>
+ %cmp = icmp slt i32 %x, 0<br>
+ br i1 %cmp, label %if.then, label %if.end3<br>
+<br>
+if.then: ; preds = %entry<br>
+ %cmp1 = icmp slt i32 %y, 0<br>
+ br i1 %cmp1, label %if.then2, label %if.end<br>
+<br>
+if.then2: ; preds = %if.then<br>
+ call void @callee()<br>
+ br label %if.end<br>
+<br>
+if.end: ; preds = %if.then2, %if.then<br>
+ br label %if.end3<br>
+<br>
+if.end3: ; preds = %if.end, %entry<br>
+ ret void<br>
+}<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>