Skip to content

Commit 4c2e937

Browse files
committed
Added genPtrCompare builder.
1 parent a60ee69 commit 4c2e937

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
630630
return result;
631631
}
632632

633+
/// Compare two pointer-like values using the given predicate.
634+
mlir::Value genPtrCompare(mlir::Location loc,
635+
mlir::arith::CmpIPredicate predicate,
636+
mlir::Value ptr1, mlir::Value ptr2) {
637+
ptr1 = createConvert(loc, getIndexType(), ptr1);
638+
ptr2 = createConvert(loc, getIndexType(), ptr2);
639+
return create<mlir::arith::CmpIOp>(loc, predicate, ptr1, ptr2);
640+
}
641+
633642
private:
634643
/// Set attributes (e.g. FastMathAttr) to \p op operation
635644
/// based on the current attributes setting.

flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,11 @@ UnpackArrayConversion::matchAndRewrite(fir::UnpackArrayOp op,
284284
fir::HeapType::get(fir::extractSequenceType(tempBox.getType()));
285285
mlir::Value tempAddr =
286286
builder.create<fir::BoxAddrOp>(loc, addrType, tempBox);
287-
mlir::Value tempAddrAsIndex =
288-
builder.createConvert(loc, indexType, tempAddr);
289287
mlir::Value originalAddr =
290288
builder.create<fir::BoxAddrOp>(loc, addrType, originalBox);
291-
originalAddr = builder.createConvert(loc, indexType, originalAddr);
292289

293-
auto isNotSame = builder.create<mlir::arith::CmpIOp>(
294-
loc, mlir::arith::CmpIPredicate::ne, tempAddrAsIndex, originalAddr);
290+
auto isNotSame = builder.genPtrCompare(loc, mlir::arith::CmpIPredicate::ne,
291+
tempAddr, originalAddr);
295292
builder.genIfThen(loc, isNotSame).genThen([&]() {});
296293
// Copy from temporary to the original.
297294
if (!op.getNoCopy())

0 commit comments

Comments
 (0)