[PATCH] D38334: Enable critical edge split for indirectbr instruction

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 14:14:34 PDT 2017


xur created this revision.

This is exposed in PGO instrumentation. I believe this is an over assert -- current logic can handle the split for the indirectbr instruction.

This patch removes the assert.


https://reviews.llvm.org/D38334

Files:
  lib/Transforms/Utils/BreakCriticalEdges.cpp
  test/Transforms/PGOProfile/indirectbr_criticaledge.ll


Index: test/Transforms/PGOProfile/indirectbr_criticaledge.ll
===================================================================
--- test/Transforms/PGOProfile/indirectbr_criticaledge.ll
+++ test/Transforms/PGOProfile/indirectbr_criticaledge.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo(i8* nocapture readonly %p) {
+entry:
+  %targets = alloca [256 x i8*], align 16
+  br label %for.body
+
+for.body:
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds [256 x i8*], [256 x i8*]* %targets, i64 0, i64 %indvars.iv
+  store i8* blockaddress(@foo, %for.cond2), i8** %arrayidx, align 8
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 256
+  br i1 %exitcond, label %for.end, label %for.body
+
+for.end:
+  %arrayidx1 = getelementptr inbounds [256 x i8*], [256 x i8*]* %targets, i64 0, i64 93
+  store i8* blockaddress(@foo, %if.end), i8** %arrayidx1, align 8
+  br label %for.cond2
+
+for.cond2:
+  %p.addr.0 = phi i8* [ %p, %for.end ], [ %incdec.ptr5, %if.end ], [ %incdec.ptr, %for.cond2 ]
+  %incdec.ptr = getelementptr inbounds i8, i8* %p.addr.0, i64 1
+  %0 = load i8, i8* %p.addr.0, align 1
+  %cond = icmp eq i8 %0, 93
+  br i1 %cond, label %if.end.preheader, label %for.cond2
+
+if.end.preheader:
+  br label %if.end
+
+if.end:
+  %p.addr.1 = phi i8* [ %incdec.ptr5, %if.end ], [ %incdec.ptr, %if.end.preheader ]
+  %incdec.ptr5 = getelementptr inbounds i8, i8* %p.addr.1, i64 1
+  %1 = load i8, i8* %p.addr.1, align 1
+  %idxprom6 = zext i8 %1 to i64
+  %arrayidx7 = getelementptr inbounds [256 x i8*], [256 x i8*]* %targets, i64 0, i64 %idxprom6
+  %2 = load i8*, i8** %arrayidx7, align 8
+  indirectbr i8* %2, [label %for.cond2, label %if.end]
+; CHECK  indirectbr i8* %2, [label %for.cond2, label %if.end.if.end_crit_edge]
+; CHECK: if.end.if.end_crit_edge:
+; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 44930229957, i32 4, i32 0)
+; CHECK: br label %if.end
+
+}
Index: lib/Transforms/Utils/BreakCriticalEdges.cpp
===================================================================
--- lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -131,9 +131,6 @@
   if (!isCriticalEdge(TI, SuccNum, Options.MergeIdenticalEdges))
     return nullptr;
 
-  assert(!isa<IndirectBrInst>(TI) &&
-         "Cannot split critical edge from IndirectBrInst");
-
   BasicBlock *TIBB = TI->getParent();
   BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38334.116879.patch
Type: text/x-patch
Size: 2782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170927/052de734/attachment.bin>


More information about the llvm-commits mailing list