-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: We already had a parallel loop specialization pass that is used to enable unrolling and consecutive vectorization by rewriting loops whose bound is defined as a min of a constant and a dynamic value into a loop with static bound (the constant) and the minimum as bound, wrapped into a conditional to dispatch between the two. This adds the same rewriting for for loops. Differential Revision: https://reviews.llvm.org/D82189
- Loading branch information
Stephan Herhut
committed
Jun 22, 2020
1 parent
46ea465
commit 4bcd08e
Showing
7 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: mlir-opt %s -for-loop-specialization -split-input-file | FileCheck %s | ||
|
||
#map0 = affine_map<()[s0, s1] -> (1024, s0 - s1)> | ||
#map1 = affine_map<()[s0, s1] -> (64, s0 - s1)> | ||
|
||
func @for(%outer: index, %A: memref<?xf32>, %B: memref<?xf32>, | ||
%C: memref<?xf32>, %result: memref<?xf32>) { | ||
%c0 = constant 0 : index | ||
%c1 = constant 1 : index | ||
%d0 = dim %A, %c0 : memref<?xf32> | ||
%b0 = affine.min #map0()[%d0, %outer] | ||
scf.for %i0 = %c0 to %b0 step %c1 { | ||
%B_elem = load %B[%i0] : memref<?xf32> | ||
%C_elem = load %C[%i0] : memref<?xf32> | ||
%sum_elem = addf %B_elem, %C_elem : f32 | ||
store %sum_elem, %result[%i0] : memref<?xf32> | ||
} | ||
return | ||
} | ||
|
||
// CHECK-LABEL: func @for( | ||
// CHECK-SAME: [[ARG0:%.*]]: index, [[ARG1:%.*]]: memref<?xf32>, [[ARG2:%.*]]: memref<?xf32>, [[ARG3:%.*]]: memref<?xf32>, [[ARG4:%.*]]: memref<?xf32>) { | ||
// CHECK: [[CST_0:%.*]] = constant 0 : index | ||
// CHECK: [[CST_1:%.*]] = constant 1 : index | ||
// CHECK: [[DIM_0:%.*]] = dim [[ARG1]], [[CST_0]] : memref<?xf32> | ||
// CHECK: [[MIN:%.*]] = affine.min #map0(){{\[}}[[DIM_0]], [[ARG0]]] | ||
// CHECK: [[CST_1024:%.*]] = constant 1024 : index | ||
// CHECK: [[PRED:%.*]] = cmpi "eq", [[MIN]], [[CST_1024]] : index | ||
// CHECK: scf.if [[PRED]] { | ||
// CHECK: scf.for [[IDX0:%.*]] = [[CST_0]] to [[CST_1024]] step [[CST_1]] { | ||
// CHECK: store | ||
// CHECK: } | ||
// CHECK: } else { | ||
// CHECK: scf.for [[IDX0:%.*]] = [[CST_0]] to [[MIN]] step [[CST_1]] { | ||
// CHECK: store | ||
// CHECK: } | ||
// CHECK: } | ||
// CHECK: return | ||
// CHECK: } |