Skip to content

Commit fba3a7c

Browse files
Integrate llvm-project@681b2413 (#20274)
Retains reverts for 418e07b7e and 1a3dc8e9c. --------- Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com> Co-authored-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
1 parent a4ca58a commit fba3a7c

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

compiler/src/iree/compiler/Codegen/Common/BlockDynamicDimensions.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "iree/compiler/Codegen/Transforms/Transforms.h"
1010
#include "iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.h"
1111
#include "iree/compiler/Dialect/LinalgExt/Transforms/Transforms.h"
12+
#include "iree/compiler/Dialect/Util/IR/UtilDialect.h"
1213
#include "iree/compiler/Dialect/Util/IR/UtilOps.h"
1314
#include "mlir/Dialect/Affine/IR/AffineOps.h"
1415
#include "mlir/Dialect/Arith/Utils/Utils.h"
@@ -233,9 +234,18 @@ static LogicalResult blockDynamicDimensions(
233234
blockDynamicDimensionsOfValue(rewriter, resultDivisibilityInfo, result);
234235
if (reshapes) {
235236
llvm::SmallPtrSet<Operation *, 1> ignoreUses;
236-
ignoreUses.insert(reshapes->expandShapeOp);
237-
rewriter.replaceAllUsesExcept(
238-
result, reshapes->collapseShapeOp.getResult(), ignoreUses);
237+
auto replaceIf = [&](OpOperand &use) {
238+
Operation *user = use.getOwner();
239+
if (user == reshapes->expandShapeOp) {
240+
return false;
241+
}
242+
if (isa<tensor::DimOp>(user)) {
243+
return false;
244+
}
245+
return true;
246+
};
247+
rewriter.replaceUsesWithIf(result, reshapes->collapseShapeOp.getResult(),
248+
replaceIf);
239249
}
240250
}
241251
return success();

compiler/src/iree/compiler/Codegen/Common/Passes.td

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def BlockDynamicDimensionsPass
2323
: Pass<"iree-codegen-block-dynamic-dimensions"> {
2424
let summary = "Expand dynamic dimensions that are known to be multiples of "
2525
"statically known values.";
26+
let dependentDialects = ["iree_compiler::IREE::Util::UtilDialect"];
2627
}
2728

2829
def BubbleUpOrdinalOpsPass : Pass<"iree-codegen-bubble-up-ordinal-ops", ""> {

compiler/src/iree/compiler/Codegen/Common/test/block_dynamic_dims.mlir

+31
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,34 @@ func.func @block_elementwise(%arg0 : tensor<?xf16>, %dim : index)
277277
// CHECK: %[[COLLAPSE:.+]] = tensor.collapse_shape %[[ELEM]]
278278
// CHECK-SAME: tensor<?x1024xf16> into tensor<?xf16>
279279
// CHECK: return %[[COLLAPSE]] : tensor<?xf16>
280+
281+
// -----
282+
283+
// Check that there are no SSA violations during blocking
284+
func.func @check_ssa_violation(%dim : index,
285+
%lhs : tensor<?xf32>, %rhs : tensor<?xf32>) -> tensor<?xf32> {
286+
%c4 = arith.constant 4 : index
287+
%0 = arith.muli %dim, %c4 overflow<nsw> : index
288+
%1 = tensor.empty(%0) : tensor<?xf32>
289+
%2 = linalg.generic {
290+
indexing_maps = [affine_map<(d0) -> (d0)>,
291+
affine_map<(d0) -> (d0)>,
292+
affine_map<(d0) -> (d0)>],
293+
iterator_types = ["parallel"]}
294+
ins(%lhs, %rhs : tensor<?xf32>, tensor<?xf32>)
295+
outs(%1 : tensor<?xf32>) {
296+
^bb0(%in: f32, %in_0: f32, %out: f32):
297+
%33 = arith.addf %in, %in_0 : f32
298+
linalg.yield %33 : f32
299+
} -> tensor<?xf32>
300+
return %2 : tensor<?xf32>
301+
}
302+
// CHECK-LABEL: func @check_ssa_violation
303+
// CHECK-SAME: %[[LHS:[a-zA-Z0-9]+]]: tensor<?xf32>
304+
// CHECK-SAME: %[[RHS:[a-zA-Z0-9]+]]: tensor<?xf32>
305+
// CHECK-DAG: %[[EXPANDED0:.+]] = tensor.expand_shape %[[LHS]]
306+
// CHECK-DAG: %[[EXPANDED1:.+]] = tensor.expand_shape %[[RHS]]
307+
// CHECK: %[[GENERIC:.+]] = linalg.generic
308+
// CHECK-SAME: ins(%[[EXPANDED0]], %[[EXPANDED1]] :
309+
// CHECK: %[[COLLAPSE:.+]] = tensor.collapse_shape %[[GENERIC]]
310+
// CHECK: return %[[COLLAPSE]]

compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ class BranchOpConversion : public EmitCConversionPattern<IREE::VM::BranchOp> {
31703170
}
31713171

31723172
Value blockArgRef =
3173-
signatureConversion.getInputMapping(index)->replacementValue;
3173+
signatureConversion.getInputMapping(index)->replacementValues[0];
31743174

31753175
assert(isa<IREE::VM::RefType>(operand.getType()));
31763176
assert(isa<emitc::PointerType>(blockArgRef.getType()));

compiler/src/iree/compiler/DispatchCreation/test/bubble_up_expand_shapes.mlir

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ util.func public @attention_v_reshape_propagation(%arg0: index,
7777
util.func @multiple_users(%arg0 : tensor<?x128xf16>,
7878
%arg1 : tensor<4x?x32x128xf16>) -> tensor<4x?x32x8x16xf16> {
7979
%c0 = arith.constant 0 : index
80-
%c1 = arith.constant 1 : index
8180
%dim = tensor.dim %arg0, %c0 : tensor<?x128xf16>
8281
%empty = tensor.empty(%dim) : tensor<4x?x32x128xf16>
8382
%0 = linalg.generic {
@@ -97,7 +96,7 @@ util.func @multiple_users(%arg0 : tensor<?x128xf16>,
9796
%2 = arith.addf %1, %b0 : f16
9897
linalg.yield %2 : f16
9998
} -> tensor<4x?x32x128xf16>
100-
%1 = tensor.dim %0, %c1 : tensor<4x?x32x128xf16>
99+
%1 = tensor.dim %arg0, %c0 : tensor<?x128xf16>
101100
%2 = tensor.expand_shape %0 [[0], [1], [2], [3, 4]] output_shape [4, %1, 32, 8, 16]
102101
: tensor<4x?x32x128xf16> into tensor<4x?x32x8x16xf16>
103102
util.return %2 : tensor<4x?x32x8x16xf16>

third_party/llvm-project

Submodule llvm-project updated 1508 files

0 commit comments

Comments
 (0)