[PATCH] D114154: [fir] Add fir.no_reassoc conversion
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 19 02:38:38 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb8207db700e6: [fir] Add fir.no_reassoc conversion (authored by clementval).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114154/new/
https://reviews.llvm.org/D114154
Files:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/convert-to-llvm.fir
Index: flang/test/Fir/convert-to-llvm.fir
===================================================================
--- flang/test/Fir/convert-to-llvm.fir
+++ flang/test/Fir/convert-to-llvm.fir
@@ -1569,3 +1569,23 @@
// CHECK-NEXT: %{{.*}} = llvm.call @custom_typeP.field_1.offset() {field = 0 : i64} : () -> i32
// CHECK-NEXT: %{{.*}} = llvm.call @custom_typeP.field_2.offset() {field = 1 : i64} : () -> i32
// CHECK-NEXT: llvm.return
+
+// -----
+
+// Check `fir.no_reassoc` conversion to LLVM IR dialect
+
+func @no_reassoc(%arg0: !fir.ref<i32>) {
+ %0 = fir.alloca i32
+ %1 = fir.load %arg0 : !fir.ref<i32>
+ %2 = fir.no_reassoc %1 : i32
+ fir.store %2 to %0 : !fir.ref<i32>
+ return
+}
+
+// CHECK-LABEL: llvm.func @no_reassoc(
+// CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr<i32>) {
+// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64
+// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr<i32>
+// CHECK: %[[LOAD:.*]] = llvm.load %[[ARG0]] : !llvm.ptr<i32>
+// CHECK: llvm.store %[[LOAD]], %[[ALLOC]] : !llvm.ptr<i32>
+// CHECK: llvm.return
Index: flang/lib/Optimizer/CodeGen/CodeGen.cpp
===================================================================
--- flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1145,6 +1145,20 @@
}
};
+/// Lower `fir.no_reassoc` to LLVM IR dialect.
+/// TODO: how do we want to enforce this in LLVM-IR? Can we manipulate the fast
+/// math flags?
+struct NoReassocOpConversion : public FIROpConversion<fir::NoReassocOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::NoReassocOp noreassoc, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ rewriter.replaceOp(noreassoc, adaptor.getOperands()[0]);
+ return success();
+ }
+};
+
/// Lower `fir.select_type` to LLVM IR dialect.
struct SelectTypeOpConversion : public FIROpConversion<fir::SelectTypeOp> {
using FIROpConversion::FIROpConversion;
@@ -2166,13 +2180,13 @@
FirEndOpConversion, HasValueOpConversion, GenTypeDescOpConversion,
GlobalLenOpConversion, GlobalOpConversion, InsertOnRangeOpConversion,
InsertValueOpConversion, IsPresentOpConversion, LoadOpConversion,
- NegcOpConversion, MulcOpConversion, SelectCaseOpConversion,
- SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion,
- ShapeOpConversion, ShapeShiftOpConversion, ShiftOpConversion,
- SliceOpConversion, StoreOpConversion, StringLitOpConversion,
- SubcOpConversion, UnboxCharOpConversion, UnboxProcOpConversion,
- UndefOpConversion, UnreachableOpConversion, ZeroOpConversion>(
- typeConverter);
+ NegcOpConversion, NoReassocOpConversion, MulcOpConversion,
+ SelectCaseOpConversion, SelectOpConversion, SelectRankOpConversion,
+ SelectTypeOpConversion, ShapeOpConversion, ShapeShiftOpConversion,
+ ShiftOpConversion, SliceOpConversion, StoreOpConversion,
+ StringLitOpConversion, SubcOpConversion, UnboxCharOpConversion,
+ UnboxProcOpConversion, UndefOpConversion, UnreachableOpConversion,
+ ZeroOpConversion>(typeConverter);
mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter,
pattern);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114154.388443.patch
Type: text/x-patch
Size: 3542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211119/6d40f8c0/attachment.bin>
More information about the llvm-commits
mailing list