<div dir="ltr">Reverted in r338442 due to buildbot unhappiness. Looks like a potential cause of this is reverse-iteration (though I haven't yet verified that this is the only thing that breaks this test)</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 31, 2018 at 1:08 PM George Burgess IV 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: gbiv<br>
Date: Tue Jul 31 13:07:46 2018<br>
New Revision: 338431<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=338431&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=338431&view=rev</a><br>
Log:<br>
Add DebugCounters to DivRemPairs<br>
<br>
For people who don't use DebugCounters, NFCI.<br>
<br>
Patch by Zhizhou Yang!<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D50033" rel="noreferrer" target="_blank">https://reviews.llvm.org/D50033</a><br>
<br>
Added:<br>
llvm/trunk/test/Other/debugcounter-divrempairs.ll<br>
Modified:<br>
llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp?rev=338431&r1=338430&r2=338431&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp?rev=338431&r1=338430&r2=338431&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/DivRemPairs.cpp Tue Jul 31 13:07:46 2018<br>
@@ -21,6 +21,7 @@<br>
#include "llvm/IR/Dominators.h"<br>
#include "llvm/IR/Function.h"<br>
#include "llvm/Pass.h"<br>
+#include "llvm/Support/DebugCounter.h"<br>
#include "llvm/Transforms/Scalar.h"<br>
#include "llvm/Transforms/Utils/BypassSlowDivision.h"<br>
using namespace llvm;<br>
@@ -29,6 +30,8 @@ using namespace llvm;<br>
STATISTIC(NumPairs, "Number of div/rem pairs");<br>
STATISTIC(NumHoisted, "Number of instructions hoisted");<br>
STATISTIC(NumDecomposed, "Number of instructions decomposed");<br>
+DEBUG_COUNTER(DRPCounter, "div-rem-pairs-transform",<br>
+ "Controls transformations in div-rem-pairs pass");<br>
<br>
/// Find matching pairs of integer div/rem ops (they have the same numerator,<br>
/// denominator, and signedness). If they exist in different basic blocks, bring<br>
@@ -93,6 +96,9 @@ static bool optimizeDivRem(Function &F,<br>
if (!DivDominates && !DT.dominates(RemInst, DivInst))<br>
continue;<br>
<br>
+ if (!DebugCounter::shouldExecute(DRPCounter))<br>
+ continue;<br>
+<br>
if (HasDivRemOp) {<br>
// The target has a single div/rem operation. Hoist the lower instruction<br>
// to make the matched pair visible to the backend.<br>
<br>
Added: llvm/trunk/test/Other/debugcounter-divrempairs.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/debugcounter-divrempairs.ll?rev=338431&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/debugcounter-divrempairs.ll?rev=338431&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Other/debugcounter-divrempairs.ll (added)<br>
+++ llvm/trunk/test/Other/debugcounter-divrempairs.ll Tue Jul 31 13:07:46 2018<br>
@@ -0,0 +1,90 @@<br>
+; RUN: opt < %s -div-rem-pairs -debug-counter=div-rem-pairs-transform-skip=1,div-rem-pairs-transform-count=1 \<br>
+; RUN: -S -mtriple=x86_64-unknown-unknown | FileCheck %s<br>
+;; Test that, with debug counters on, we only skip the first div-rem-pairs opportunity, optimize one after it,<br>
+;; and then ignore all the others. There is 1 optimization opportunity in f1, 2 in f2, and another 1 in f3,<br>
+;; only the first one in f2 will be performed.<br>
+<br>
+define i64 @f1(i64 %a, i64 %b) {<br>
+; CHECK-LABEL: @f1(<br>
+; CHECK-NEXT: entry:<br>
+; CHECK-NEXT: [[REM:%.*]] = urem i64 %a, %b<br>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[REM]], 42<br>
+; CHECK-NEXT: br i1 [[CMP]], label %if, label %end<br>
+; CHECK: if:<br>
+; CHECK-NEXT: [[DIV:%.*]] = udiv i64 %a, %b<br>
+; CHECK-NEXT: br label %end<br>
+; CHECK: end:<br>
+; CHECK-NEXT: [[RET:%.*]] = phi i64 [ [[DIV]], %if ], [ 3, %entry ]<br>
+; CHECK-NEXT: ret i64 [[RET]]<br>
+;<br>
+entry:<br>
+ %rem = urem i64 %a, %b<br>
+ %cmp = icmp eq i64 %rem, 42<br>
+ br i1 %cmp, label %if, label %end<br>
+<br>
+if:<br>
+ %div = udiv i64 %a, %b<br>
+ br label %end<br>
+<br>
+end:<br>
+ %ret = phi i64 [ %div, %if ], [ 3, %entry ]<br>
+ ret i64 %ret<br>
+}<br>
+<br>
+define i16 @f2(i16 %a, i16 %b) {<br>
+; CHECK-LABEL: @f2(<br>
+; CHECK-NEXT: entry:<br>
+; CHECK-NEXT: [[DIV1:%.*]] = sdiv i16 %a, %b<br>
+; CHECK-NEXT: [[REM1:%.*]] = srem i16 %a, %b<br>
+; CHECK-NEXT: [[DIV2:%.*]] = udiv i16 %a, %b<br>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[DIV1]], 42<br>
+; CHECK-NEXT: br i1 [[CMP]], label %if, label %end<br>
+; CHECK: if:<br>
+; CHECK-NEXT: [[REM2:%.*]] = urem i16 %a, %b<br>
+; CHECK-NEXT: br label %end<br>
+; CHECK: end:<br>
+; CHECK-NEXT: [[RET:%.*]] = phi i16 [ [[REM1]], %if ], [ 3, %entry ]<br>
+; CHECK-NEXT: ret i16 [[RET]]<br>
+;<br>
+entry:<br>
+ %div1 = sdiv i16 %a, %b<br>
+ %div2 = udiv i16 %a, %b<br>
+ %cmp = icmp eq i16 %div1, 42<br>
+ br i1 %cmp, label %if, label %end<br>
+<br>
+if:<br>
+ %rem1 = srem i16 %a, %b<br>
+ %rem2 = urem i16 %a, %b<br>
+ br label %end<br>
+<br>
+end:<br>
+ %ret = phi i16 [ %rem1, %if ], [ 3, %entry ]<br>
+ ret i16 %ret<br>
+}<br>
+<br>
+define i32 @f3(i32 %a, i32 %b) {<br>
+; CHECK-LABEL: @f3(<br>
+; CHECK-NEXT: entry:<br>
+; CHECK-NEXT: [[REM:%.*]] = srem i32 %a, %b<br>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[REM]], 42<br>
+; CHECK-NEXT: br i1 [[CMP]], label %if, label %end<br>
+; CHECK: if:<br>
+; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 %a, %b<br>
+; CHECK-NEXT: br label %end<br>
+; CHECK: end:<br>
+; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[DIV]], %if ], [ 3, %entry ]<br>
+; CHECK-NEXT: ret i32 [[RET]]<br>
+;<br>
+entry:<br>
+ %rem = srem i32 %a, %b<br>
+ %cmp = icmp eq i32 %rem, 42<br>
+ br i1 %cmp, label %if, label %end<br>
+<br>
+if:<br>
+ %div = sdiv i32 %a, %b<br>
+ br label %end<br>
+<br>
+end:<br>
+ %ret = phi i32 [ %div, %if ], [ 3, %entry ]<br>
+ ret i32 %ret<br>
+}<br>
\ No newline at end of file<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>