[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) (PR #85562)

2024-03-17 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/85562
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: backport [C++20] [Moduls] Avoid computing odr hash for functions from comparing constraint expression (PR #84723)

2024-03-17 Thread Chuanqi Xu via llvm-branch-commits

ChuanqiXu9 wrote:

@tstellar Could we backport this to 18.x?

https://github.com/llvm/llvm-project/pull/84723
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Completes the tzdb class. (PR #82157)

2024-03-17 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/82157

>From 7a742c0e564ffa37ad299cf6186faadd61e34d29 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 23 Sep 2022 18:33:20 +0200
Subject: [PATCH] [libc++][chrono] Completes the tzdb class.

It adds the missing member functions of the tzdb class and adds the free
functions that use these member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
---
 libcxx/include/__chrono/tzdb.h| 35 
 libcxx/include/__chrono/tzdb_list.h   | 10 +++
 libcxx/include/chrono |  5 ++
 libcxx/modules/std/chrono.inc |  4 +-
 libcxx/src/tzdb.cpp   | 59 ++
 ...rono.nodiscard_extensions.compile.pass.cpp |  8 ++
 .../chrono.nodiscard_extensions.verify.cpp|  8 ++
 .../time.zone.db.access/current_zone.pass.cpp | 77 ++
 .../time.zone.db.access/locate_zone.pass.cpp  | 62 +++
 .../time.zone.db.tzdb/current_zone.pass.cpp   | 79 +++
 .../time.zone.db.tzdb/locate_zone.pass.cpp| 64 +++
 11 files changed, 409 insertions(+), 2 deletions(-)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/locate_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/locate_zone.pass.cpp

diff --git a/libcxx/include/__chrono/tzdb.h b/libcxx/include/__chrono/tzdb.h
index 45c20f279f9c96..667d2406645658 100644
--- a/libcxx/include/__chrono/tzdb.h
+++ b/libcxx/include/__chrono/tzdb.h
@@ -16,6 +16,7 @@
 // Enable the contents of the header only when libc++ was built with 
experimental features enabled.
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
+#  include <__algorithm/ranges_lower_bound.h>
 #  include <__chrono/leap_second.h>
 #  include <__chrono/time_zone.h>
 #  include <__chrono/time_zone_link.h>
@@ -43,6 +44,40 @@ struct tzdb {
   vector links;
 
   vector leap_seconds;
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* 
__locate_zone(string_view __name) const {
+if (const time_zone* __result = __find_in_zone(__name); __result)
+  return __result;
+
+if (auto __it = ranges::lower_bound(links, __name, {}, 
&time_zone_link::name);
+__it != links.end() && __it->name() == __name)
+  if (const time_zone* __result = __find_in_zone(__it->target()); __result)
+return __result;
+
+return nullptr;
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const time_zone* 
locate_zone(string_view __name) const {
+if (const time_zone* __result = __locate_zone(__name))
+  return __result;
+
+std::__throw_runtime_error("tzdb: requested time zone not found");
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const 
time_zone* current_zone() const {
+return __current_zone();
+  }
+
+private:
+  _LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) 
const noexcept {
+if (auto __it = ranges::lower_bound(zones, __name, {}, &time_zone::name);
+__it != zones.end() && __it->name() == __name)
+  return std::addressof(*__it);
+
+return nullptr;
+  }
+
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const 
time_zone* __current_zone() const;
 };
 
 } // namespace chrono
diff --git a/libcxx/include/__chrono/tzdb_list.h 
b/libcxx/include/__chrono/tzdb_list.h
index 112e04ff2ee6ac..d812312287f16e 100644
--- a/libcxx/include/__chrono/tzdb_list.h
+++ b/libcxx/include/__chrono/tzdb_list.h
@@ -17,6 +17,7 @@
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
 #  include <__availability>
+#  include <__chrono/time_zone.h>
 #  include <__chrono/tzdb.h>
 #  include <__config>
 #  include <__fwd/string.h>
@@ -74,6 +75,15 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB 
_LIBCPP_HIDE_FROM_ABI inline con
   return get_tzdb_list().front();
 }
 
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone*
+locate_zone(string_view __name) {
+  return get_tzdb().locate_zone(__name);
+}
+
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone* current_zone() {
+  return get_tzdb().current_zone();
+}
+
 _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
 
 _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI 
string remote_version();
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 4dd43137b71820..8fdc30a3624dfc 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -689,6 +689,9 @@ struct tzdb {
   vector  zones;
   vector links;
   vectorleap_seconds;
+
+  const time_zone* locate_zone(string_view tz_name) const;
+  const time_zone* curr

[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan edited 
https://github.com/llvm/llvm-project/pull/84955
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -0,0 +1,47 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Test that we don't crash when there is a call operation in the combiner
+
+omp.reduction.declare @add_f32 : f32
+init {
+^bb0(%arg: f32):
+  %0 = llvm.mlir.constant(0.0 : f32) : f32
+  omp.yield (%0 : f32)
+}
+combiner {
+^bb1(%arg0: f32, %arg1: f32):
+// test this call here:
+  llvm.call @test_call() : () -> ()
+  %1 = llvm.fadd %arg0, %arg1 : f32
+  omp.yield (%1 : f32)
+}
+atomic {
+^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
+  %2 = llvm.load %arg3 : !llvm.ptr -> f32
+  llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
+  omp.yield
+}
+
+llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) {
+  %c1 = llvm.mlir.constant(1 : i32) : i32
+  %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
+  omp.parallel {
+omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr)
+for (%iv) : i64 = (%lb) to (%ub) step (%step) {
+  %1 = llvm.mlir.constant(2.0 : f32) : f32
+  %2 = llvm.load %prv : !llvm.ptr -> f32
+  %3 = llvm.fadd %1, %2 : f32
+  llvm.store %3, %prv : f32, !llvm.ptr
+  omp.yield
+}
+omp.terminator
+  }
+  llvm.return
+}
+
+llvm.func @test_call() -> ()

kiranchandramohan wrote:

> Why do we need any OpenMp constructs here?

`forgetMapping` is only used in the OpenMP translation.

https://github.com/llvm/llvm-project/pull/84955
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -0,0 +1,47 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Test that we don't crash when there is a call operation in the combiner
+
+omp.reduction.declare @add_f32 : f32
+init {
+^bb0(%arg: f32):
+  %0 = llvm.mlir.constant(0.0 : f32) : f32
+  omp.yield (%0 : f32)
+}
+combiner {
+^bb1(%arg0: f32, %arg1: f32):
+// test this call here:
+  llvm.call @test_call() : () -> ()
+  %1 = llvm.fadd %arg0, %arg1 : f32
+  omp.yield (%1 : f32)
+}
+atomic {
+^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
+  %2 = llvm.load %arg3 : !llvm.ptr -> f32
+  llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
+  omp.yield
+}

kiranchandramohan wrote:

Can the atomic region be removed?

https://github.com/llvm/llvm-project/pull/84955
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan commented:

Some minor comments about the test.

https://github.com/llvm/llvm-project/pull/84955
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -0,0 +1,47 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Test that we don't crash when there is a call operation in the combiner
+
+omp.reduction.declare @add_f32 : f32
+init {
+^bb0(%arg: f32):
+  %0 = llvm.mlir.constant(0.0 : f32) : f32
+  omp.yield (%0 : f32)
+}
+combiner {
+^bb1(%arg0: f32, %arg1: f32):
+// test this call here:
+  llvm.call @test_call() : () -> ()
+  %1 = llvm.fadd %arg0, %arg1 : f32
+  omp.yield (%1 : f32)
+}
+atomic {
+^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
+  %2 = llvm.load %arg3 : !llvm.ptr -> f32
+  llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
+  omp.yield
+}
+
+llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) {
+  %c1 = llvm.mlir.constant(1 : i32) : i32
+  %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
+  omp.parallel {
+omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr)

kiranchandramohan wrote:

Can the reduction be moved to `omp.parallel`? And the `omp.wsloop` removed?

https://github.com/llvm/llvm-project/pull/84955
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan edited 
https://github.com/llvm/llvm-project/pull/84958
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -92,10 +93,42 @@ std::string 
ReductionProcessor::getReductionName(llvm::StringRef name,
   if (isByRef)
 byrefAddition = "_byref";
 
-  return (llvm::Twine(name) +
-  (ty.isIntOrIndex() ? llvm::Twine("_i_") : llvm::Twine("_f_")) +
-  llvm::Twine(ty.getIntOrFloatBitWidth()) + byrefAddition)
-  .str();
+  if (fir::isa_trivial(ty))
+return (llvm::Twine(name) +
+(ty.isIntOrIndex() ? llvm::Twine("_i_") : llvm::Twine("_f_")) +
+llvm::Twine(ty.getIntOrFloatBitWidth()) + byrefAddition)
+.str();
+
+  // creates a name like reduction_i_64_box_ux4x3
+  if (auto boxTy = mlir::dyn_cast_or_null(ty)) {
+// TODO: support for allocatable boxes:
+// !fir.box>>
+fir::SequenceType seqTy = fir::unwrapRefType(boxTy.getEleTy())
+  .dyn_cast_or_null();
+if (!seqTy)
+  return {};
+
+std::string prefix = getReductionName(
+name, fir::unwrapSeqOrBoxedSeqType(ty), /*isByRef=*/false);
+if (prefix.empty())
+  return {};
+std::stringstream tyStr;
+tyStr << prefix << "_box_";
+bool first = true;
+for (std::int64_t extent : seqTy.getShape()) {
+  if (first)
+first = false;
+  else
+tyStr << "x";
+  if (extent == seqTy.getUnknownExtent())
+tyStr << 'u'; // I'm not sure that '?' is safe in symbol names
+  else
+tyStr << extent;
+}
+return (tyStr.str() + byrefAddition).str();
+  }
+
+  return {};

kiranchandramohan wrote:

There is a getTypeAsString 
(https://github.com/llvm/llvm-project/blob/07b18c5e1b7a8ac9347f945da5ffaecc4515f391/flang/lib/Optimizer/Dialect/FIRType.cpp#L520).
 Can that be used? If it changes existing reduction names then we can move to 
this in a separate patch.

https://github.com/llvm/llvm-project/pull/84958
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -283,13 +316,166 @@ mlir::Value ReductionProcessor::createScalarCombiner(
   return reductionOp;
 }
 
+/// Create reduction combiner region for reduction variables which are boxed
+/// arrays
+static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
+   ReductionProcessor::ReductionIdentifier redId,
+   fir::BaseBoxType boxTy, mlir::Value lhs,
+   mlir::Value rhs) {
+  fir::SequenceType seqTy =
+  mlir::dyn_cast_or_null(boxTy.getEleTy());
+  // TODO: support allocatable arrays: !fir.box>>
+  if (!seqTy || seqTy.hasUnknownShape())
+TODO(loc, "Unsupported boxed type in OpenMP reduction");
+
+  // load fir.ref>
+  mlir::Value lhsAddr = lhs;
+  lhs = builder.create(loc, lhs);
+  rhs = builder.create(loc, rhs);
+
+  const unsigned rank = seqTy.getDimension();
+  llvm::SmallVector extents;
+  extents.reserve(rank);
+  llvm::SmallVector lbAndExtents;
+  lbAndExtents.reserve(rank * 2);
+
+  // Get box lowerbounds and extents:
+  mlir::Type idxTy = builder.getIndexType();
+  for (unsigned i = 0; i < rank; ++i) {
+// TODO: ideally we want to hoist box reads out of the critical section.
+// We could do this by having box dimensions in block arguments like
+// OpenACC does
+mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i);
+auto dimInfo =
+builder.create(loc, idxTy, idxTy, idxTy, lhs, dim);
+extents.push_back(dimInfo.getExtent());
+lbAndExtents.push_back(dimInfo.getLowerBound());
+lbAndExtents.push_back(dimInfo.getExtent());
+  }
+
+  auto shapeShiftTy = fir::ShapeShiftType::get(builder.getContext(), rank);
+  auto shapeShift =
+  builder.create(loc, shapeShiftTy, lbAndExtents);
+
+  // Iterate over array elements, applying the equivalent scalar reduction:
+
+  // A hlfir::elemental here gets inlined with a temporary so create the
+  // loop nest directly.
+  // This function already controls all of the code in this region so we
+  // know this won't miss any opportuinties for clever elemental inlining
+  hlfir::LoopNest nest =
+  hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true);
+  builder.setInsertionPointToStart(nest.innerLoop.getBody());
+  mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
+  auto lhsEleAddr = builder.create(
+  loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{},
+  nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{});
+  auto rhsEleAddr = builder.create(
+  loc, refTy, rhs, shapeShift, /*slice=*/mlir::Value{},
+  nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{});
+  auto lhsEle = builder.create(loc, lhsEleAddr);
+  auto rhsEle = builder.create(loc, rhsEleAddr);
+  mlir::Value scalarReduction = ReductionProcessor::createScalarCombiner(
+  builder, loc, redId, refTy, lhsEle, rhsEle);
+  builder.create(loc, scalarReduction, lhsEleAddr);
+
+  builder.setInsertionPointAfter(nest.outerLoop);
+  builder.create(loc, lhsAddr);
+}
+
+// generate combiner region for reduction operations
+static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
+ReductionProcessor::ReductionIdentifier redId,
+mlir::Type ty, mlir::Value lhs, mlir::Value rhs,
+bool isByRef) {
+  ty = fir::unwrapRefType(ty);
+
+  if (fir::isa_trivial(ty)) {
+mlir::Value lhsLoaded = builder.loadIfRef(loc, lhs);
+mlir::Value rhsLoaded = builder.loadIfRef(loc, rhs);
+
+mlir::Value result = ReductionProcessor::createScalarCombiner(
+builder, loc, redId, ty, lhsLoaded, rhsLoaded);
+if (isByRef) {
+  builder.create(loc, result, lhs);
+  builder.create(loc, lhs);
+} else {
+  builder.create(loc, result);
+}
+return;
+  }
+  // all arrays should have been boxed
+  if (auto boxTy = mlir::dyn_cast(ty)) {
+genBoxCombiner(builder, loc, redId, boxTy, lhs, rhs);
+return;
+  }
+
+  TODO(loc, "OpenMP genCombiner for unsupported reduction variable type");
+}
+
+static mlir::Value
+createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
+  const ReductionProcessor::ReductionIdentifier redId,
+  mlir::Type type, bool isByRef) {
+  mlir::Type ty = fir::unwrapRefType(type);
+  mlir::Value initValue = ReductionProcessor::getReductionInitValue(
+  loc, fir::unwrapSeqOrBoxedSeqType(ty), redId, builder);
+
+  if (fir::isa_trivial(ty)) {
+if (isByRef) {
+  mlir::Value alloca = builder.create(loc, ty);
+  builder.createStoreWithConvert(loc, initValue, alloca);
+  return alloca;
+}
+// by val
+return initValue;
+  }
+
+  // all arrays are boxed
+  if (auto boxTy = mlir::dyn_cast_or_null(ty)) {
+assert(isByRef && "passing arrays by value is unsupported");
+// TODO: support allocatable arrays: !fir.box>>
+mlir::Type innerTy = fir::extractSequenceType(boxTy);
+if (!mlir::isa(innerTy))
+  

[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -0,0 +1,74 @@
+! RUN: bbc -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+program reduce
+integer, dimension(3) :: i = 0
+
+!$omp parallel reduction(+:i)
+i(1) = 1
+i(2) = 2
+i(3) = 3

kiranchandramohan wrote:

Is the test written to deliberately not use the reduction operation in the body?

https://github.com/llvm/llvm-project/pull/84958
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan commented:

Nice work. Have a few minor comments.

https://github.com/llvm/llvm-project/pull/84958
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -283,13 +316,166 @@ mlir::Value ReductionProcessor::createScalarCombiner(
   return reductionOp;
 }
 
+/// Create reduction combiner region for reduction variables which are boxed
+/// arrays
+static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
+   ReductionProcessor::ReductionIdentifier redId,
+   fir::BaseBoxType boxTy, mlir::Value lhs,
+   mlir::Value rhs) {
+  fir::SequenceType seqTy =
+  mlir::dyn_cast_or_null(boxTy.getEleTy());
+  // TODO: support allocatable arrays: !fir.box>>
+  if (!seqTy || seqTy.hasUnknownShape())
+TODO(loc, "Unsupported boxed type in OpenMP reduction");
+
+  // load fir.ref>
+  mlir::Value lhsAddr = lhs;
+  lhs = builder.create(loc, lhs);
+  rhs = builder.create(loc, rhs);
+
+  const unsigned rank = seqTy.getDimension();
+  llvm::SmallVector extents;
+  extents.reserve(rank);
+  llvm::SmallVector lbAndExtents;
+  lbAndExtents.reserve(rank * 2);
+
+  // Get box lowerbounds and extents:
+  mlir::Type idxTy = builder.getIndexType();
+  for (unsigned i = 0; i < rank; ++i) {
+// TODO: ideally we want to hoist box reads out of the critical section.
+// We could do this by having box dimensions in block arguments like
+// OpenACC does
+mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i);
+auto dimInfo =
+builder.create(loc, idxTy, idxTy, idxTy, lhs, dim);
+extents.push_back(dimInfo.getExtent());
+lbAndExtents.push_back(dimInfo.getLowerBound());
+lbAndExtents.push_back(dimInfo.getExtent());
+  }
+
+  auto shapeShiftTy = fir::ShapeShiftType::get(builder.getContext(), rank);
+  auto shapeShift =
+  builder.create(loc, shapeShiftTy, lbAndExtents);
+
+  // Iterate over array elements, applying the equivalent scalar reduction:
+
+  // A hlfir::elemental here gets inlined with a temporary so create the
+  // loop nest directly.
+  // This function already controls all of the code in this region so we
+  // know this won't miss any opportuinties for clever elemental inlining
+  hlfir::LoopNest nest =
+  hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true);
+  builder.setInsertionPointToStart(nest.innerLoop.getBody());
+  mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
+  auto lhsEleAddr = builder.create(
+  loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{},
+  nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{});
+  auto rhsEleAddr = builder.create(
+  loc, refTy, rhs, shapeShift, /*slice=*/mlir::Value{},
+  nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{});
+  auto lhsEle = builder.create(loc, lhsEleAddr);
+  auto rhsEle = builder.create(loc, rhsEleAddr);
+  mlir::Value scalarReduction = ReductionProcessor::createScalarCombiner(
+  builder, loc, redId, refTy, lhsEle, rhsEle);
+  builder.create(loc, scalarReduction, lhsEleAddr);
+
+  builder.setInsertionPointAfter(nest.outerLoop);
+  builder.create(loc, lhsAddr);
+}
+
+// generate combiner region for reduction operations
+static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
+ReductionProcessor::ReductionIdentifier redId,
+mlir::Type ty, mlir::Value lhs, mlir::Value rhs,
+bool isByRef) {
+  ty = fir::unwrapRefType(ty);
+
+  if (fir::isa_trivial(ty)) {
+mlir::Value lhsLoaded = builder.loadIfRef(loc, lhs);
+mlir::Value rhsLoaded = builder.loadIfRef(loc, rhs);
+
+mlir::Value result = ReductionProcessor::createScalarCombiner(
+builder, loc, redId, ty, lhsLoaded, rhsLoaded);
+if (isByRef) {
+  builder.create(loc, result, lhs);
+  builder.create(loc, lhs);
+} else {
+  builder.create(loc, result);
+}
+return;
+  }
+  // all arrays should have been boxed
+  if (auto boxTy = mlir::dyn_cast(ty)) {
+genBoxCombiner(builder, loc, redId, boxTy, lhs, rhs);
+return;
+  }
+
+  TODO(loc, "OpenMP genCombiner for unsupported reduction variable type");
+}
+
+static mlir::Value
+createReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc,
+  const ReductionProcessor::ReductionIdentifier redId,
+  mlir::Type type, bool isByRef) {
+  mlir::Type ty = fir::unwrapRefType(type);
+  mlir::Value initValue = ReductionProcessor::getReductionInitValue(
+  loc, fir::unwrapSeqOrBoxedSeqType(ty), redId, builder);
+
+  if (fir::isa_trivial(ty)) {
+if (isByRef) {
+  mlir::Value alloca = builder.create(loc, ty);
+  builder.createStoreWithConvert(loc, initValue, alloca);
+  return alloca;
+}
+// by val
+return initValue;
+  }
+
+  // all arrays are boxed
+  if (auto boxTy = mlir::dyn_cast_or_null(ty)) {
+assert(isByRef && "passing arrays by value is unsupported");
+// TODO: support allocatable arrays: !fir.box>>
+mlir::Type innerTy = fir::extractSequenceType(boxTy);
+if (!mlir::isa(innerTy))
+  

[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)

2024-03-17 Thread Kiran Chandramohan via llvm-branch-commits


@@ -465,8 +642,8 @@ void ReductionProcessor::addReductionDecl(
 if (auto declOp = symVal.getDefiningOp())
   symVal = declOp.getBase();
 auto redType = symVal.getType().cast();
-assert(redType.getEleTy().isIntOrIndexOrFloat() &&
-   "Unsupported reduction type");
+if (!redType.getEleTy().isIntOrIndexOrFloat())
+  TODO(currentLocation, "User Defined Reduction on arrays");

kiranchandramohan wrote:

Nit: We don't support complex type now. So this could be due to being a complex 
type as well.

https://github.com/llvm/llvm-project/pull/84958
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AVR] Remove earlyclobber from LDDRdPtrQ (#85277) (PR #85512)

2024-03-17 Thread Ben Shi via llvm-branch-commits

benshi001 wrote:

> @benshi001 What do you think about merging this PR to the release branch?

Yes. I think so. Because this is a bug fix.

https://github.com/llvm/llvm-project/pull/85512
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-17 Thread Ben Shi via llvm-branch-commits

https://github.com/benshi001 approved this pull request.


https://github.com/llvm/llvm-project/pull/85422
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64][GlobalISel] Avoid splitting loads of large vector types into individual element loads (PR #85042)

2024-03-17 Thread Dhruv Chawla via llvm-branch-commits

https://github.com/dc03-work closed 
https://github.com/llvm/llvm-project/pull/85042
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64][GlobalISel] Avoid splitting loads of large vector types into individual element loads (PR #85042)

2024-03-17 Thread Dhruv Chawla via llvm-branch-commits

https://github.com/dc03-work edited 
https://github.com/llvm/llvm-project/pull/85042
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64][GlobalISel] Avoid splitting loads of large vector types into individual element loads (PR #85042)

2024-03-17 Thread Dhruv Chawla via llvm-branch-commits

dc03-work wrote:

Manually landed this PR in 
https://github.com/llvm/llvm-project/commit/208a9850e6a4b64ad6311361735d27a9c6cbd8ec,
 because I still don't understand how stacking on GitHub works...

https://github.com/llvm/llvm-project/pull/85042
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits