Skip to content

Commit 5419623

Browse files
authored
[MLIR][LLVM] Remove bitcast pattern from type consistency pass (#87755)
This commit removes the no longer required bitcast inserting pattern in LLVM dialect's type consistency pattern. This was previously required to enable Mem2Reg and SROA to promote accesses that had different types. Recent changes to both passes added direct support for this feature to them, so the pattern has no further use.
1 parent 9708d09 commit 5419623

File tree

3 files changed

+1
-56
lines changed

3 files changed

+1
-56
lines changed

mlir/include/mlir/Dialect/LLVMIR/Transforms/TypeConsistency.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ class SplitStores : public OpRewritePattern<StoreOp> {
5656
PatternRewriter &rewrite) const override;
5757
};
5858

59-
/// Transforms type-inconsistent stores, aka stores where the type hint of
60-
/// the address contradicts the value stored, by inserting a bitcast if
61-
/// possible.
62-
class BitcastStores : public OpRewritePattern<StoreOp> {
63-
public:
64-
using OpRewritePattern::OpRewritePattern;
65-
66-
LogicalResult matchAndRewrite(StoreOp store,
67-
PatternRewriter &rewriter) const override;
68-
};
69-
7059
/// Splits GEPs with more than two indices into multiple GEPs with exactly
7160
/// two indices. The created GEPs are then guaranteed to index into only
7261
/// one aggregate at a time.

mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ static Type isElementTypeInconsistent(Value addr, Type expectedType) {
4242
return elemType;
4343
}
4444

45-
/// Checks that two types are the same or can be bitcast into one another.
46-
static bool areBitcastCompatible(DataLayout &layout, Type lhs, Type rhs) {
47-
return lhs == rhs || (!isa<LLVMStructType, LLVMArrayType>(lhs) &&
48-
!isa<LLVMStructType, LLVMArrayType>(rhs) &&
49-
layout.getTypeSize(lhs) == layout.getTypeSize(rhs));
50-
}
51-
5245
//===----------------------------------------------------------------------===//
5346
// CanonicalizeAlignedGep
5447
//===----------------------------------------------------------------------===//
@@ -518,26 +511,6 @@ LogicalResult SplitStores::matchAndRewrite(StoreOp store,
518511
return success();
519512
}
520513

521-
LogicalResult BitcastStores::matchAndRewrite(StoreOp store,
522-
PatternRewriter &rewriter) const {
523-
Type sourceType = store.getValue().getType();
524-
Type typeHint = isElementTypeInconsistent(store.getAddr(), sourceType);
525-
if (!typeHint) {
526-
// Nothing to do, since it is already consistent.
527-
return failure();
528-
}
529-
530-
auto dataLayout = DataLayout::closest(store);
531-
if (!areBitcastCompatible(dataLayout, typeHint, sourceType))
532-
return failure();
533-
534-
auto bitcastOp =
535-
rewriter.create<BitcastOp>(store.getLoc(), typeHint, store.getValue());
536-
rewriter.modifyOpInPlace(store,
537-
[&] { store.getValueMutable().assign(bitcastOp); });
538-
return success();
539-
}
540-
541514
LogicalResult SplitGEP::matchAndRewrite(GEPOp gepOp,
542515
PatternRewriter &rewriter) const {
543516
FailureOr<Type> typeHint = getRequiredConsistentGEPType(gepOp);
@@ -588,7 +561,6 @@ struct LLVMTypeConsistencyPass
588561
RewritePatternSet rewritePatterns(&getContext());
589562
rewritePatterns.add<CanonicalizeAlignedGep>(&getContext());
590563
rewritePatterns.add<SplitStores>(&getContext(), maxVectorSplitSize);
591-
rewritePatterns.add<BitcastStores>(&getContext());
592564
rewritePatterns.add<SplitGEP>(&getContext());
593565
FrozenRewritePatternSet frozen(std::move(rewritePatterns));
594566

mlir/test/Dialect/LLVMIR/type-consistency.mlir

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ llvm.func @coalesced_store_floats(%arg: i64) {
157157
// CHECK: %[[SHR:.*]] = llvm.lshr %[[ARG]], %[[CST32]] : i64
158158
// CHECK: %[[TRUNC:.*]] = llvm.trunc %[[SHR]] : i64 to i32
159159
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ALLOCA]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"foo", (f32, f32)>
160-
// CHECK: %[[BIT_CAST:.*]] = llvm.bitcast %[[TRUNC]] : i32 to f32
161-
// CHECK: llvm.store %[[BIT_CAST]], %[[GEP]]
160+
// CHECK: llvm.store %[[TRUNC]], %[[GEP]]
162161
llvm.store %arg, %1 : i64, !llvm.ptr
163162
// CHECK-NOT: llvm.store %[[ARG]], %[[ALLOCA]]
164163
llvm.return
@@ -327,21 +326,6 @@ llvm.func @vector_write_split_struct(%arg: vector<2xi64>) {
327326

328327
// -----
329328

330-
// CHECK-LABEL: llvm.func @bitcast_insertion
331-
// CHECK-SAME: %[[ARG:.*]]: i32
332-
llvm.func @bitcast_insertion(%arg: i32) {
333-
%0 = llvm.mlir.constant(1 : i32) : i32
334-
// CHECK: %[[ALLOCA:.*]] = llvm.alloca %{{.*}} x f32
335-
%1 = llvm.alloca %0 x f32 : (i32) -> !llvm.ptr
336-
// CHECK: %[[BIT_CAST:.*]] = llvm.bitcast %[[ARG]] : i32 to f32
337-
// CHECK: llvm.store %[[BIT_CAST]], %[[ALLOCA]]
338-
llvm.store %arg, %1 : i32, !llvm.ptr
339-
// CHECK-NOT: llvm.store %[[ARG]], %[[ALLOCA]]
340-
llvm.return
341-
}
342-
343-
// -----
344-
345329
// CHECK-LABEL: llvm.func @gep_split
346330
// CHECK-SAME: %[[ARG:.*]]: i64
347331
llvm.func @gep_split(%arg: i64) {

0 commit comments

Comments
 (0)