<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 4, 2016 at 8:40 AM, Hans Wennborg via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hans<br>
Date: Wed May  4 10:40:57 2016<br>
New Revision: 268512<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268512&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268512&view=rev</a><br>
Log:<br>
[SimplifyCFG] isSafeToSpeculateStore now ignores debug info<br>
<br>
This patch fixes PR27615.<br>
<br>
@llvm.dbg.value instructions no longer count towards the maximum number of<br>
instructions to look back at in the instruction list when searching for a<br>
store instruction. This should make the output consistent between debug and<br>
non-debug build.<br>
<br>
Patch by Henric Karlsson <<a href="mailto:henric.karlsson@ericsson.com">henric.karlsson@ericsson.com</a>>!<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D19912" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19912</a><br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=268512&r1=268511&r2=268512&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=268512&r1=268511&r2=268512&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Wed May  4 10:40:57 2016<br>
@@ -1448,10 +1448,14 @@ static Value *isSafeToSpeculateStore(Ins<br>
   Value *StorePtr = StoreToHoist->getPointerOperand();<br>
<br>
   // Look for a store to the same pointer in BrBB.<br>
-  unsigned MaxNumInstToLookAt = 10;<br>
+  unsigned MaxNumInstToLookAt = 9;<br>
   for (BasicBlock::reverse_iterator RI = BrBB->rbegin(),<br>
-       RE = BrBB->rend(); RI != RE && (--MaxNumInstToLookAt); ++RI) {<br>
+       RE = BrBB->rend(); RI != RE && MaxNumInstToLookAt; ++RI) {<br>
     Instruction *CurI = &*RI;<br>
+    // Skip debug info.<br>
+    if (isa<DbgInfoIntrinsic>(CurI))<br>
+      continue;<br>
+    --MaxNumInstToLookAt;<br>
<br>
     // Could be calling an instruction that effects memory like free().<br>
     if (CurI->mayHaveSideEffects() && !isa<StoreInst>(CurI))<br>
<br>
Added: llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll?rev=268512&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll?rev=268512&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll (added)<br>
+++ llvm/trunk/test/Transforms/SimplifyCFG/PR27615-simplify-cond-br.ll Wed May  4 10:40:57 2016<br>
@@ -0,0 +1,68 @@<br>
+; RUN: opt -S -simplifycfg -strip-debug < %s | FileCheck %s<br>
+; RUN: opt -S -simplifycfg < %s | FileCheck %s<br>
+<br>
+; Test case for BUG-27615<br></blockquote><div><br>I was going to say that we usually refer to bugs by PRXXXXX, but then I saw you did in the file name - so perhaps this comment doesn't add much?<br><br>Also, I'd tend to prefer a test case that just describes what it tests (both in name & text) standalone, rather than needing to refer to a bug to understand the intent. But that's not a strong habit within the project, so it's hardly something I'll advocate strongly for.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+; Test that simplify cond branch produce same result for debug and non-debug builds<br>
+; CHECK: select i1 %or.cond, i32 -1, i32 5<br>
+; CHECK-NOT: bb1:<br>
+<br>
+; ModuleID = './csmith107.i.debug.ll'<br>
+source_filename = "./csmith107.i.debug.ll"<br>
+<br>
+@a = global i16 0<br>
+@b = global i32 0<br>
+@c = global i16* null<br>
+<br>
+<br>
+; Function Attrs: nounwind<br>
+define i16 @fn1() #3 !dbg !15 {<br>
+bb2:<br>
+  store i32 -1, i32* @b, align 1<br>
+  %_tmp1.pre = load i16, i16* @a, align 1, !dbg !19<br>
+  %_tmp2.pre = load i16*, i16** @c, align 1<br>
+  tail call void @llvm.dbg.value(metadata i16 6, i64 0, metadata !22, metadata !23), !dbg !24<br>
+  tail call void @llvm.dbg.value(metadata i16 %_tmp1.pre, i64 0, metadata !25, metadata !23), !dbg !19<br>
+  %_tmp3 = load i16, i16* %_tmp2.pre, align 1<br>
+  %_tmp4 = icmp ne i16 %_tmp3, 0<br>
+  %_tmp6 = icmp ne i16 %_tmp1.pre, 0<br>
+  %or.cond = and i1 %_tmp6, %_tmp4<br>
+  br i1 %or.cond, label %bb5, label %bb1<br>
+<br>
+bb1:                                              ; preds = %bb2<br>
+  store i32 5, i32* @b, align 1<br>
+  br label %bb5<br>
+<br>
+bb5:                                              ; preds = %bb1, %bb2<br>
+  ret i16 0<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #4<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!12, !13}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "FlexC Compiler v6.36 (LLVM)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3)<br>
+!1 = !DIFile(filename: "csmith107.i.c", directory: "/tmp")<br>
+!2 = !{}<br>
+!3 = !{!4, !6, !10}<br>
+!4 = !DIGlobalVariable(name: "a", scope: null, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, variable: i16* @a)<br>
+!5 = !DIBasicType(name: "int", size: 16, align: 16, encoding: DW_ATE_signed)<br>
+!6 = !DIGlobalVariable(name: "b", scope: null, file: !1, line: 3, type: !7, isLocal: false, isDefinition: true, variable: i32* @b)<br>
+!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !1, line: 1, baseType: !8)<br>
+!8 = !DIDerivedType(tag: DW_TAG_typedef, name: "__u32_t", file: !1, baseType: !9)<br>
+!9 = !DIBasicType(name: "unsigned long", size: 32, align: 16, encoding: DW_ATE_unsigned)<br>
+!10 = !DIGlobalVariable(name: "c", scope: null, file: !1, line: 4, type: !11, isLocal: false, isDefinition: true, variable: i16** @c)<br>
+!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 16, align: 16)<br>
+!12 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!13 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!15 = distinct !DISubprogram(name: "fn1", scope: !1, file: !1, line: 5, type: !16, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0, variables: !2)<br>
+!16 = !DISubroutineType(types: !17)<br>
+!17 = !{!5}<br>
+!19 = !DILocation(line: 8, column: 16, scope: !20)<br>
+!20 = !DILexicalBlock(scope: !15, file: !1, line: 7, column: 29)<br>
+!22 = !DILocalVariable(name: "d", scope: !20, line: 8, type: !5)<br>
+!23 = !DIExpression()<br>
+!24 = !DILocation(line: 8, column: 9, scope: !20)<br>
+!25 = !DILocalVariable(name: "e", scope: !20, line: 8, type: !5)<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">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><br></div></div>