[llvm-branch-commits] [clang] [llvm] [Clang][OMPX] Add the code generation for multi-dim `num_teams` (PR #101407)

2024-08-01 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/101407
___
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] [llvm] [Clang][OMPX] Add the code generation for multi-dim `num_teams` (PR #101407)

2024-08-01 Thread Alexey Bataev via llvm-branch-commits


@@ -9576,6 +9576,20 @@ static void genMapInfo(const OMPExecutableDirective , 
CodeGenFunction ,
 MappedVarSet, CombinedInfo);
   genMapInfo(MEHandler, CGF, CombinedInfo, OMPBuilder, MappedVarSet);
 }
+
+static void emitNumTeamsForBareTargetDirective(
+CodeGenFunction , const OMPExecutableDirective ,
+llvm::SmallVectorImpl ) {

alexey-bataev wrote:

Ah, missed it

https://github.com/llvm/llvm-project/pull/101407
___
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] [llvm] [Clang][OMPX] Add the code generation for multi-dim `num_teams` (PR #101407)

2024-08-01 Thread Alexey Bataev via llvm-branch-commits


@@ -9576,6 +9576,20 @@ static void genMapInfo(const OMPExecutableDirective , 
CodeGenFunction ,
 MappedVarSet, CombinedInfo);
   genMapInfo(MEHandler, CGF, CombinedInfo, OMPBuilder, MappedVarSet);
 }
+
+static void emitNumTeamsForBareTargetDirective(
+CodeGenFunction , const OMPExecutableDirective ,
+llvm::SmallVectorImpl ) {

alexey-bataev wrote:

```suggestion
llvm::ArrayRef NumTeams) {
```

https://github.com/llvm/llvm-project/pull/101407
___
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/19.x: [SLP] Order clustered load base pointers by ascending offsets (#100653) (PR #101033)

2024-07-29 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/101033
___
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] [clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (PR #98633)

2024-07-12 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/98633
___
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] [clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (PR #98633)

2024-07-12 Thread Alexey Bataev via llvm-branch-commits


@@ -9090,14 +9090,15 @@ void 
SemaOpenMP::ActOnOpenMPLoopInitialization(SourceLocation ForLoc,
   isOpenMPSimdDirective(DKind)
   ? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
   : OMPC_private;
+  auto isOpenMPTaskloopDirective = [](OpenMPDirectiveKind DK) {

alexey-bataev wrote:

IsOpenMPTaskloopDirective

https://github.com/llvm/llvm-project/pull/98633
___
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] [clang][OpenMP] Remove compound directives from `checkNestingOfRegions` (PR #98387)

2024-07-10 Thread Alexey Bataev via llvm-branch-commits


@@ -4805,6 +4811,7 @@ static bool checkNestingOfRegions(Sema , const 
DSAStackTy *Stack,
 << getOpenMPDirectiveName(CurrentRegion);
 return true;
   }
+

alexey-bataev wrote:

Remove this extra line

https://github.com/llvm/llvm-project/pull/98387
___
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] [clang][OpenMP] Remove compound directives from `checkNestingOfRegions` (PR #98387)

2024-07-10 Thread Alexey Bataev via llvm-branch-commits


@@ -4828,26 +4835,28 @@ static bool checkNestingOfRegions(Sema , const 
DSAStackTy *Stack,
 << (SemaRef.LangOpts.OpenMP >= 50 ? 1 : 0);
 return CurrentRegion != OMPD_simd;
   }
-  if (ParentRegion == OMPD_atomic) {
+
+  if (EnclosingConstruct == OMPD_atomic) {

alexey-bataev wrote:

Remove extra empty line here and in other places

https://github.com/llvm/llvm-project/pull/98387
___
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] [clang][OpenMP] Rewrite `getOpenMPCaptureRegions` in terms of leafs (PR #97110)

2024-07-01 Thread Alexey Bataev via llvm-branch-commits


@@ -747,105 +747,79 @@ void clang::getOpenMPCaptureRegions(
   assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
   assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
 
-  switch (DKind) {
-  case OMPD_metadirective:
-CaptureRegions.push_back(OMPD_metadirective);
-break;
-  case OMPD_parallel:
-  case OMPD_parallel_for:
-  case OMPD_parallel_for_simd:
-  case OMPD_parallel_master:
-  case OMPD_parallel_masked:
-  case OMPD_parallel_sections:
-  case OMPD_distribute_parallel_for:
-  case OMPD_distribute_parallel_for_simd:
-  case OMPD_parallel_loop:
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_target_teams:
-  case OMPD_target_teams_distribute:
-  case OMPD_target_teams_distribute_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_teams);
-break;
-  case OMPD_teams:
-  case OMPD_teams_distribute:
-  case OMPD_teams_distribute_simd:
-CaptureRegions.push_back(OMPD_teams);
-break;
-  case OMPD_target:
-  case OMPD_target_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-break;
-  case OMPD_teams_loop:
-  case OMPD_teams_distribute_parallel_for:
-  case OMPD_teams_distribute_parallel_for_simd:
-CaptureRegions.push_back(OMPD_teams);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_target_parallel:
-  case OMPD_target_parallel_for:
-  case OMPD_target_parallel_for_simd:
-  case OMPD_target_parallel_loop:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_task:
-  case OMPD_target_enter_data:
-  case OMPD_target_exit_data:
-  case OMPD_target_update:
-CaptureRegions.push_back(OMPD_task);
-break;
-  case OMPD_taskloop:
-  case OMPD_taskloop_simd:
-  case OMPD_master_taskloop:
-  case OMPD_master_taskloop_simd:
-  case OMPD_masked_taskloop:
-  case OMPD_masked_taskloop_simd:
-CaptureRegions.push_back(OMPD_taskloop);
-break;
-  case OMPD_parallel_masked_taskloop:
-  case OMPD_parallel_masked_taskloop_simd:
-  case OMPD_parallel_master_taskloop:
-  case OMPD_parallel_master_taskloop_simd:
-CaptureRegions.push_back(OMPD_parallel);
-CaptureRegions.push_back(OMPD_taskloop);
-break;
-  case OMPD_target_teams_loop:
-  case OMPD_target_teams_distribute_parallel_for:
-  case OMPD_target_teams_distribute_parallel_for_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_teams);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_nothing:
-CaptureRegions.push_back(OMPD_nothing);
-break;
-  case OMPD_loop:
-// TODO: 'loop' may require different capture regions depending on the bind
-// clause or the parent directive when there is no bind clause. Use
-// OMPD_unknown for now.
-  case OMPD_simd:
-  case OMPD_for:
-  case OMPD_for_simd:
-  case OMPD_sections:
-  case OMPD_single:
-  case OMPD_taskgroup:
-  case OMPD_distribute:
-  case OMPD_ordered:
-  case OMPD_target_data:
-  case OMPD_distribute_simd:
-  case OMPD_scope:
-  case OMPD_dispatch:
+  auto getRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
+assert(isLeafConstruct(LKind) && "Epecting leaf directive");
+switch (LKind) {
+case OMPD_metadirective:
+  CaptureRegions.push_back(OMPD_metadirective);
+  break;
+case OMPD_nothing:
+  CaptureRegions.push_back(OMPD_nothing);
+  break;
+case OMPD_parallel:
+  CaptureRegions.push_back(OMPD_parallel);
+  break;
+case OMPD_target:
+  CaptureRegions.push_back(OMPD_task);
+  CaptureRegions.push_back(OMPD_target);
+  break;
+case OMPD_task:
+case OMPD_target_enter_data:
+case OMPD_target_exit_data:
+case OMPD_target_update:
+  CaptureRegions.push_back(OMPD_task);
+  break;
+case OMPD_teams:
+  CaptureRegions.push_back(OMPD_teams);
+  break;
+case OMPD_taskloop:
+  CaptureRegions.push_back(OMPD_taskloop);
+  break;
+case OMPD_loop:
+  // TODO: 'loop' may require different capture regions depending on the
+  // bind clause or the parent directive when there is no bind clause.
+  // If any of the directives that push regions here are parents of 'loop',
+  // assume 'parallel'. Otherwise do nothing.
+  if (!CaptureRegions.empty() &&
+  !llvm::is_contained(CaptureRegions, OMPD_parallel))
+CaptureRegions.push_back(OMPD_parallel);
+  break;
+case OMPD_dispatch:
+case OMPD_distribute:
+case OMPD_for:
+case OMPD_masked:
+case OMPD_master:
+case OMPD_ordered:
+case OMPD_scope:
+case OMPD_sections:
+case OMPD_simd:
+case OMPD_single:
+case OMPD_target_data:
+case OMPD_taskgroup:
+  // These directives (when standalone) use OMPD_unknown as the region,
+  

[llvm-branch-commits] [clang] [clang][OpenMP] Rewrite `getOpenMPCaptureRegions` in terms of leafs (PR #97110)

2024-07-01 Thread Alexey Bataev via llvm-branch-commits


@@ -747,105 +747,79 @@ void clang::getOpenMPCaptureRegions(
   assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
   assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
 
-  switch (DKind) {
-  case OMPD_metadirective:
-CaptureRegions.push_back(OMPD_metadirective);
-break;
-  case OMPD_parallel:
-  case OMPD_parallel_for:
-  case OMPD_parallel_for_simd:
-  case OMPD_parallel_master:
-  case OMPD_parallel_masked:
-  case OMPD_parallel_sections:
-  case OMPD_distribute_parallel_for:
-  case OMPD_distribute_parallel_for_simd:
-  case OMPD_parallel_loop:
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_target_teams:
-  case OMPD_target_teams_distribute:
-  case OMPD_target_teams_distribute_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_teams);
-break;
-  case OMPD_teams:
-  case OMPD_teams_distribute:
-  case OMPD_teams_distribute_simd:
-CaptureRegions.push_back(OMPD_teams);
-break;
-  case OMPD_target:
-  case OMPD_target_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-break;
-  case OMPD_teams_loop:
-  case OMPD_teams_distribute_parallel_for:
-  case OMPD_teams_distribute_parallel_for_simd:
-CaptureRegions.push_back(OMPD_teams);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_target_parallel:
-  case OMPD_target_parallel_for:
-  case OMPD_target_parallel_for_simd:
-  case OMPD_target_parallel_loop:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_task:
-  case OMPD_target_enter_data:
-  case OMPD_target_exit_data:
-  case OMPD_target_update:
-CaptureRegions.push_back(OMPD_task);
-break;
-  case OMPD_taskloop:
-  case OMPD_taskloop_simd:
-  case OMPD_master_taskloop:
-  case OMPD_master_taskloop_simd:
-  case OMPD_masked_taskloop:
-  case OMPD_masked_taskloop_simd:
-CaptureRegions.push_back(OMPD_taskloop);
-break;
-  case OMPD_parallel_masked_taskloop:
-  case OMPD_parallel_masked_taskloop_simd:
-  case OMPD_parallel_master_taskloop:
-  case OMPD_parallel_master_taskloop_simd:
-CaptureRegions.push_back(OMPD_parallel);
-CaptureRegions.push_back(OMPD_taskloop);
-break;
-  case OMPD_target_teams_loop:
-  case OMPD_target_teams_distribute_parallel_for:
-  case OMPD_target_teams_distribute_parallel_for_simd:
-CaptureRegions.push_back(OMPD_task);
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_teams);
-CaptureRegions.push_back(OMPD_parallel);
-break;
-  case OMPD_nothing:
-CaptureRegions.push_back(OMPD_nothing);
-break;
-  case OMPD_loop:
-// TODO: 'loop' may require different capture regions depending on the bind
-// clause or the parent directive when there is no bind clause. Use
-// OMPD_unknown for now.
-  case OMPD_simd:
-  case OMPD_for:
-  case OMPD_for_simd:
-  case OMPD_sections:
-  case OMPD_single:
-  case OMPD_taskgroup:
-  case OMPD_distribute:
-  case OMPD_ordered:
-  case OMPD_target_data:
-  case OMPD_distribute_simd:
-  case OMPD_scope:
-  case OMPD_dispatch:
+  auto getRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {

alexey-bataev wrote:

```suggestion
  auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
```


https://github.com/llvm/llvm-project/pull/97110
___
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] [clang][OpenMP] Implement `isOpenMPCapturingDirective` (PR #97090)

2024-06-28 Thread Alexey Bataev via llvm-branch-commits


@@ -709,10 +709,44 @@ bool 
clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
   return Cat == Category::Executable || Cat == Category::Subsidiary;
 }
 
+bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
+  if (isOpenMPExecutableDirective(DKind)) {
+switch (DKind) {
+case OMPD_atomic:
+case OMPD_barrier:
+case OMPD_cancel:
+case OMPD_cancellation_point:
+case OMPD_critical:
+case OMPD_depobj:
+case OMPD_error:
+case OMPD_flush:
+case OMPD_masked:
+case OMPD_master:
+case OMPD_section:
+case OMPD_taskwait:
+case OMPD_taskyield:
+  return false;
+default:
+  return !isOpenMPLoopTransformationDirective(DKind);
+}
+  }
+  // Non-executable directives.
+  switch (DKind) {
+  case OMPD_metadirective:
+  case OMPD_nothing:
+return true;
+  default:
+break;
+  }
+  return false;
+}
+
 void clang::getOpenMPCaptureRegions(
 SmallVectorImpl ,
 OpenMPDirectiveKind DKind) {
   assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
+  assert(isOpenMPCapturingDirective(DKind));

alexey-bataev wrote:

Add assertion message

https://github.com/llvm/llvm-project/pull/97090
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -15980,7 +15985,44 @@ StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(
  "affected loops");
 
   // Decode the permutation clause.
-  constexpr uint64_t Permutation[] = {1, 0};
+  SmallVector Permutation;
+  if (!PermutationClause) {
+Permutation = {1, 0};
+  } else {
+ArrayRef PermArgs = PermutationClause->getArgsRefs();
+llvm::BitVector Flags(PermArgs.size());
+for (Expr *PermArg : PermArgs) {
+  std::optional PermCstExpr =
+  PermArg->getIntegerConstantExpr(Context);
+  if (!PermCstExpr)
+continue;
+  uint64_t PermInt = PermCstExpr->getZExtValue();
+  assert(1 <= PermInt && PermInt <= NumLoops &&
+ "Must be a permutation; diagnostic emitted in "
+ "ActOnOpenMPPermutationClause");
+  if (Flags[PermInt - 1]) {
+SourceRange ExprRange(PermArg->getBeginLoc(), PermArg->getEndLoc());
+Diag(PermArg->getExprLoc(),
+ diag::err_omp_interchange_permutation_value_repeated)
+<< PermInt << ExprRange;
+continue;
+  }
+  Flags[PermInt - 1] = true;
+
+  Permutation.push_back(PermInt - 1);
+}
+
+if (Permutation.size() != NumLoops)
+  return StmtError();
+  }
+
+  // Nothing to transform with trivial permutation.
+  if (NumLoops <= 1 || llvm::all_of(llvm::enumerate(Permutation), [](auto p) {

alexey-bataev wrote:

`auto P`

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -15972,6 +15971,12 @@ StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(
 return OMPInterchangeDirective::Create(Context, StartLoc, EndLoc, Clauses,
NumLoops, AStmt, nullptr, nullptr);
 
+  // An invalid expression in the permutation clause is set to nullptr in
+  // ActOnOpenMPPermutationClause.
+  if (PermutationClause && llvm::any_of(PermutationClause->getArgsRefs(),
+[](Expr *E) { return !E; }))

alexey-bataev wrote:

Use is_contained

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -9861,13 +9842,19 @@ buildPreInits(ASTContext ,
 
 /// Build pre-init statement for the given statements.
 static Stmt *buildPreInits(ASTContext , ArrayRef PreInits) {
-  if (PreInits.empty())
-return nullptr;
-
-  SmallVector Stmts;
-  for (Stmt *S : PreInits)
-appendFlattendedStmtList(Stmts, S);
-  return CompoundStmt::Create(Context, PreInits, FPOptionsOverride(), {}, {});
+  if (!PreInits.empty()) {
+SmallVector Stmts;
+for (Stmt *S : PreInits) {
+  // Do not nest CompoundStmts.
+  if (auto *CS = dyn_cast(S)) {
+llvm::append_range(Stmts, CS->body());
+continue;
+  }
+  Stmts.push_back(S);
+}
+return CompoundStmt::Create(Context, PreInits, FPOptionsOverride(), {}, 
{});
+  }
+  return nullptr;

alexey-bataev wrote:

Original code should work correctly, no?

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -15209,7 +15206,7 @@ static void collectLoopStmts(Stmt *AStmt, 
MutableArrayRef LoopStmts) {
 LoopStmts[Cnt] = CurStmt;
 return false;
   });
-  assert(!is_contained(LoopStmts, nullptr) &&
+  assert(llvm::all_of(LoopStmts, [](Stmt *LoopStmt) { return LoopStmt; }) &&

alexey-bataev wrote:

restore

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -1774,6 +1793,18 @@ void 
OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) {
   OS << ")";
 }
 
+void OMPClausePrinter::VisitOMPPermutationClause(OMPPermutationClause *Node) {
+  OS << "permutation(";
+  bool First = true;
+  for (Expr *Size : Node->getArgsRefs()) {
+if (!First)
+  OS << ", ";
+Size->printPretty(OS, nullptr, Policy, 0);
+First = false;
+  }

alexey-bataev wrote:

`llvm::interleaveComma(Node->getArgsRefs(), OS,
[&](const Expr *E) { E->printPretty(OS, nullptr, 
Policy, 0); });`

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -9970,9 +9957,12 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 // Search for pre-init declared variables that need to be captured
 // to be referenceable inside the directive.
 SmallVector Constituents;
-appendFlattendedStmtList(Constituents, DependentPreInits);
+if (auto *CS = dyn_cast(DependentPreInits))

alexey-bataev wrote:

Restore original

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -15149,8 +15139,15 @@ bool SemaOpenMP::checkTransformableLoopNest(
   DependentPreInits = Dir->getPreInits();
 else
   llvm_unreachable("Unhandled loop transformation");
-
-appendFlattendedStmtList(OriginalInits.back(), DependentPreInits);
+if (!DependentPreInits)

alexey-bataev wrote:

Restore

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -870,6 +870,106 @@ class OMPSizesClause final
   }
 };
 
+/// This class represents the 'permutation' clause in the
+/// '#pragma omp interchange' directive.
+///
+/// \code{c}
+///   #pragma omp interchange permutation(2,1)
+///   for (int i = 0; i < 64; ++i)
+/// for (int j = 0; j < 64; ++j)
+/// \endcode
+class OMPPermutationClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
+  friend class OMPClauseReader;
+  friend class llvm::TrailingObjects;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Number of arguments in the clause, and hence also the number of loops to
+  /// be permuted.
+  unsigned NumLoops;
+
+  /// Sets the permutation index expressions.
+  void setArgRefs(ArrayRef VL) {
+assert(VL.size() == NumLoops);
+std::copy(VL.begin(), VL.end(),

alexey-bataev wrote:

Use llvm::copy

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -870,6 +870,106 @@ class OMPSizesClause final
   }
 };
 
+/// This class represents the 'permutation' clause in the
+/// '#pragma omp interchange' directive.
+///
+/// \code{c}
+///   #pragma omp interchange permutation(2,1)
+///   for (int i = 0; i < 64; ++i)
+/// for (int j = 0; j < 64; ++j)
+/// \endcode
+class OMPPermutationClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
+  friend class OMPClauseReader;
+  friend class llvm::TrailingObjects;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Number of arguments in the clause, and hence also the number of loops to
+  /// be permuted.
+  unsigned NumLoops;
+
+  /// Sets the permutation index expressions.
+  void setArgRefs(ArrayRef VL) {
+assert(VL.size() == NumLoops);

alexey-bataev wrote:

Add assertion message

https://github.com/llvm/llvm-project/pull/92030
___
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] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits


@@ -15937,6 +15945,160 @@ StmtResult 
SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt,
  buildPreInits(Context, PreInits));
 }
 
+StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(
+ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc) {
+  ASTContext  = getASTContext();
+  DeclContext *CurContext = SemaRef.CurContext;
+  Scope *CurScope = SemaRef.getCurScope();
+
+  // Empty statement should only be possible if there already was an error.
+  if (!AStmt)
+return StmtError();
+
+  // interchange without permutation clause swaps two loops.
+  constexpr size_t NumLoops = 2;
+
+  // Verify and diagnose loop nest.
+  SmallVector LoopHelpers(NumLoops);
+  Stmt *Body = nullptr;
+  SmallVector, 2> OriginalInits;
+  if (!checkTransformableLoopNest(OMPD_interchange, AStmt, NumLoops,
+  LoopHelpers, Body, OriginalInits))
+return StmtError();
+
+  // Delay interchange to when template is completely instantiated.
+  if (CurContext->isDependentContext())
+return OMPInterchangeDirective::Create(Context, StartLoc, EndLoc, Clauses,
+   NumLoops, AStmt, nullptr, nullptr);
+
+  assert(LoopHelpers.size() == NumLoops &&
+ "Expecting loop iteration space dimensionaly to match number of "
+ "affected loops");
+  assert(OriginalInits.size() == NumLoops &&
+ "Expecting loop iteration space dimensionaly to match number of "
+ "affected loops");
+
+  // Decode the permutation clause.
+  constexpr uint64_t Permutation[] = {1, 0};
+
+  // Find the affected loops.
+  SmallVector LoopStmts(NumLoops, nullptr);
+  collectLoopStmts(AStmt, LoopStmts);
+
+  // Collect pre-init statements on the order before the permuation.
+  SmallVector PreInits;
+  for (auto I : llvm::seq(NumLoops)) {
+OMPLoopBasedDirective::HelperExprs  = LoopHelpers[I];
+
+assert(LoopHelper.Counters.size() == 1 &&
+   "Single-dimensional loop iteration space expected");
+auto *OrigCntVar = cast(LoopHelper.Counters.front());
+
+std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();
+addLoopPreInits(Context, LoopHelper, LoopStmts[I], OriginalInits[I],
+PreInits);
+  }
+
+  SmallVector PermutedIndVars;
+  PermutedIndVars.resize(NumLoops);

alexey-bataev wrote:

SmallVector PermutedIndVars(NumLoops);

https://github.com/llvm/llvm-project/pull/93022
___
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] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev edited 
https://github.com/llvm/llvm-project/pull/93022
___
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] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)

2024-05-22 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG with a nit

https://github.com/llvm/llvm-project/pull/93022
___
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] [flang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #92030)

2024-05-21 Thread Alexey Bataev via llvm-branch-commits


@@ -5779,6 +5779,80 @@ class OMPReverseDirective final : public 
OMPLoopTransformationDirective {
   }
 };
 
+/// Represents the '#pragma omp interchange' loop transformation directive.
+///
+/// \code{c}
+///   #pragma omp interchange
+///   for (int i = 0; i < m; ++i)
+/// for (int j = 0; j < n; ++j)
+///   ..
+/// \endcode
+class OMPInterchangeDirective final : public OMPLoopTransformationDirective {

alexey-bataev wrote:

If the directive itslef can be used without clauses, need to introduce the 
directive at first and then add a clause in a separate patch

https://github.com/llvm/llvm-project/pull/92030
___
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] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)

2024-05-21 Thread Alexey Bataev via llvm-branch-commits


@@ -5711,6 +5712,71 @@ class OMPUnrollDirective final : public 
OMPLoopTransformationDirective {
   }
 };
 
+/// Represents the '#pragma omp reverse' loop transformation directive.
+///
+/// \code
+/// #pragma omp reverse
+/// for (int i = 0; i < n; ++i)
+///   ...
+/// \endcode
+class OMPReverseDirective final : public OMPLoopTransformationDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+
+  /// Offsets of child members.
+  enum {
+PreInitsOffset = 0,
+TransformedStmtOffset,
+  };
+
+  explicit OMPReverseDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPLoopTransformationDirective(OMPReverseDirectiveClass,
+   llvm::omp::OMPD_reverse, StartLoc,
+   EndLoc, 1) {}
+
+  void setPreInits(Stmt *PreInits) {
+Data->getChildren()[PreInitsOffset] = PreInits;
+  }
+
+  void setTransformedStmt(Stmt *S) {
+Data->getChildren()[TransformedStmtOffset] = S;
+  }
+
+public:
+  /// Create a new AST node representation for '#pragma omp reverse'.
+  ///
+  /// \param C Context of the AST.
+  /// \param StartLoc  Location of the introducer (e.g. the 'omp' token).
+  /// \param EndLocLocation of the directive's end (e.g. the tok::eod).
+  /// \param AssociatedStmt  The outermost associated loop.
+  /// \param TransformedStmt The loop nest after tiling, or nullptr in
+  ///dependent contexts.
+  /// \param PreInits   Helper preinits statements for the loop nest.
+  static OMPReverseDirective *
+  Create(const ASTContext , SourceLocation StartLoc, SourceLocation EndLoc,
+ Stmt *AssociatedStmt, Stmt *TransformedStmt, Stmt *PreInits);
+
+  /// Build an empty '#pragma omp reverse' AST node for deserialization.
+  ///
+  /// \param C  Context of the AST.
+  /// \param NumClauses Number of clauses to allocate.
+  static OMPReverseDirective *CreateEmpty(const ASTContext ,
+  unsigned NumClauses);

alexey-bataev wrote:

No need for NumClauses, always 0

https://github.com/llvm/llvm-project/pull/92916
___
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] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)

2024-05-21 Thread Alexey Bataev via llvm-branch-commits


@@ -5711,6 +5712,73 @@ class OMPUnrollDirective final : public 
OMPLoopTransformationDirective {
   }
 };
 
+/// Represents the '#pragma omp reverse' loop transformation directive.
+///
+/// \code
+/// #pragma omp reverse
+/// for (int i = 0; i < n; ++i)
+///   ...
+/// \endcode
+class OMPReverseDirective final : public OMPLoopTransformationDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+
+  /// Offsets of child members.
+  enum {
+PreInitsOffset = 0,
+TransformedStmtOffset,
+  };
+
+  explicit OMPReverseDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPLoopTransformationDirective(OMPReverseDirectiveClass,
+   llvm::omp::OMPD_reverse, StartLoc,
+   EndLoc, 1) {}
+
+  void setPreInits(Stmt *PreInits) {
+Data->getChildren()[PreInitsOffset] = PreInits;
+  }
+
+  void setTransformedStmt(Stmt *S) {
+Data->getChildren()[TransformedStmtOffset] = S;
+  }
+
+public:
+  /// Create a new AST node representation for '#pragma omp reverse'.
+  ///
+  /// \param C Context of the AST.
+  /// \param StartLoc  Location of the introducer (e.g. the 'omp' token).
+  /// \param EndLocLocation of the directive's end (e.g. the tok::eod).
+  /// \param Clauses   The directive's clauses.
+  /// \param AssociatedStmt  The outermost associated loop.
+  /// \param TransformedStmt The loop nest after tiling, or nullptr in
+  ///dependent contexts.
+  /// \param PreInits   Helper preinits statements for the loop nest.
+  static OMPReverseDirective *
+  Create(const ASTContext , SourceLocation StartLoc, SourceLocation EndLoc,
+ ArrayRef Clauses, Stmt *AssociatedStmt,

alexey-bataev wrote:

If it does not have clauses, this param must be excluded

https://github.com/llvm/llvm-project/pull/92916
___
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] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)

2024-05-21 Thread Alexey Bataev via llvm-branch-commits


@@ -6546,6 +6547,10 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
 Res = ActOnOpenMPUnrollDirective(ClausesWithImplicit, AStmt, StartLoc,
  EndLoc);
 break;
+  case OMPD_reverse:
+Res = ActOnOpenMPReverseDirective(ClausesWithImplicit, AStmt, StartLoc,

alexey-bataev wrote:

Do not pass clauses here, if they are not expected, just assert, that it should 
be empty

https://github.com/llvm/llvm-project/pull/92916
___
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 Revert "[SLP]Fix a crash if the argument of call was affected by minbitwidth analysis." (PR #91682)

2024-05-15 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/91682
___
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] [flang] [llvm] [openmp] [Clang][OpenMP] Add reverse and interchange directives (PR #92030)

2024-05-14 Thread Alexey Bataev via llvm-branch-commits


@@ -15745,6 +15760,388 @@ StmtResult 
SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses,
 buildPreInits(Context, PreInits));
 }
 
+StmtResult
+SemaOpenMP::ActOnOpenMPReverseDirective(ArrayRef Clauses,
+Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc) {
+  ASTContext  = getASTContext();
+  Scope *CurScope = SemaRef.getCurScope();
+  assert(Clauses.empty() && "reverse directive does not accept any clauses; "
+"must have beed checked before");
+
+  // Empty statement should only be possible if there already was an error.
+  if (!AStmt)
+return StmtError();
+
+  constexpr unsigned NumLoops = 1;
+  Stmt *Body = nullptr;
+  SmallVector LoopHelpers(
+  NumLoops);
+  SmallVector, NumLoops + 1> OriginalInits;
+  if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers,
+  Body, OriginalInits))
+return StmtError();
+
+  // Delay applying the transformation to when template is completely
+  // instantiated.
+  if (SemaRef.CurContext->isDependentContext())
+return OMPReverseDirective::Create(Context, StartLoc, EndLoc, Clauses,
+   AStmt, nullptr, nullptr);
+
+  assert(LoopHelpers.size() == NumLoops &&
+ "Expecting a single-dimensional loop iteration space");
+  assert(OriginalInits.size() == NumLoops &&
+ "Expecting a single-dimensional loop iteration space");
+  OMPLoopBasedDirective::HelperExprs  = LoopHelpers.front();
+
+  // Find the loop statement.
+  Stmt *LoopStmt = nullptr;
+  collectLoopStmts(AStmt, {LoopStmt});
+
+  // Determine the PreInit declarations.
+  SmallVector PreInits;
+  addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits);
+
+  auto *IterationVarRef = cast(LoopHelper.IterationVarRef);
+  QualType IVTy = IterationVarRef->getType();
+  uint64_t IVWidth = Context.getTypeSize(IVTy);
+  auto *OrigVar = cast(LoopHelper.Counters.front());
+
+  // Iteration variable SourceLocations.
+  SourceLocation OrigVarLoc = OrigVar->getExprLoc();
+  SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc();
+  SourceLocation OrigVarLocEnd = OrigVar->getEndLoc();
+
+  // Locations pointing to the transformation.
+  SourceLocation TransformLoc = StartLoc;
+  SourceLocation TransformLocBegin = StartLoc;
+  SourceLocation TransformLocEnd = EndLoc;
+
+  // Internal variable names.
+  std::string OrigVarName = OrigVar->getNameInfo().getAsString();
+  std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str();
+  std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str();
+  std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str();
+
+  // LoopHelper.Updates will read the logical iteration number from
+  // LoopHelper.IterationVarRef, compute the value of the user loop counter of
+  // that logical iteration from it, then assign it to the user loop counter
+  // variable. We cannot directly use LoopHelper.IterationVarRef as the
+  // induction variable of the generated loop because it may cause an 
underflow:
+  // \code
+  //   for (unsigned i = 0; i < n; ++i)
+  // body(i);
+  // \endcode
+  //
+  // Naive reversal:
+  // \code
+  //   for (unsigned i = n-1; i >= 0; ++i)

alexey-bataev wrote:

```suggestion
  //   for (unsigned i = n-1; i >= 0; --i)
```


https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [openmp] [Clang][OpenMP] Add reverse and interchange directives (PR #92030)

2024-05-14 Thread Alexey Bataev via llvm-branch-commits


@@ -15745,6 +15760,388 @@ StmtResult 
SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses,
 buildPreInits(Context, PreInits));
 }
 
+StmtResult
+SemaOpenMP::ActOnOpenMPReverseDirective(ArrayRef Clauses,
+Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc) {
+  ASTContext  = getASTContext();
+  Scope *CurScope = SemaRef.getCurScope();
+  assert(Clauses.empty() && "reverse directive does not accept any clauses; "
+"must have beed checked before");
+
+  // Empty statement should only be possible if there already was an error.
+  if (!AStmt)
+return StmtError();
+
+  constexpr unsigned NumLoops = 1;
+  Stmt *Body = nullptr;
+  SmallVector LoopHelpers(
+  NumLoops);
+  SmallVector, NumLoops + 1> OriginalInits;
+  if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers,
+  Body, OriginalInits))
+return StmtError();
+
+  // Delay applying the transformation to when template is completely
+  // instantiated.
+  if (SemaRef.CurContext->isDependentContext())
+return OMPReverseDirective::Create(Context, StartLoc, EndLoc, Clauses,
+   AStmt, nullptr, nullptr);
+
+  assert(LoopHelpers.size() == NumLoops &&
+ "Expecting a single-dimensional loop iteration space");
+  assert(OriginalInits.size() == NumLoops &&
+ "Expecting a single-dimensional loop iteration space");
+  OMPLoopBasedDirective::HelperExprs  = LoopHelpers.front();
+
+  // Find the loop statement.
+  Stmt *LoopStmt = nullptr;
+  collectLoopStmts(AStmt, {LoopStmt});
+
+  // Determine the PreInit declarations.
+  SmallVector PreInits;
+  addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits);
+
+  auto *IterationVarRef = cast(LoopHelper.IterationVarRef);
+  QualType IVTy = IterationVarRef->getType();
+  uint64_t IVWidth = Context.getTypeSize(IVTy);
+  auto *OrigVar = cast(LoopHelper.Counters.front());
+
+  // Iteration variable SourceLocations.
+  SourceLocation OrigVarLoc = OrigVar->getExprLoc();
+  SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc();
+  SourceLocation OrigVarLocEnd = OrigVar->getEndLoc();
+
+  // Locations pointing to the transformation.
+  SourceLocation TransformLoc = StartLoc;
+  SourceLocation TransformLocBegin = StartLoc;
+  SourceLocation TransformLocEnd = EndLoc;
+
+  // Internal variable names.
+  std::string OrigVarName = OrigVar->getNameInfo().getAsString();
+  std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str();
+  std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str();
+  std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str();
+
+  // LoopHelper.Updates will read the logical iteration number from
+  // LoopHelper.IterationVarRef, compute the value of the user loop counter of
+  // that logical iteration from it, then assign it to the user loop counter
+  // variable. We cannot directly use LoopHelper.IterationVarRef as the
+  // induction variable of the generated loop because it may cause an 
underflow:
+  // \code
+  //   for (unsigned i = 0; i < n; ++i)
+  // body(i);
+  // \endcode
+  //
+  // Naive reversal:
+  // \code
+  //   for (unsigned i = n-1; i >= 0; ++i)
+  // body(i);
+  // \endcode
+  //
+  // Instead, we introduce a new iteration variable representing the logical
+  // iteration counter of the original loop, convert it to the logical 
iteration
+  // number of the reversed loop, then let LoopHelper.Updates compute the 
user's
+  // loop iteration variable from it.
+  // \code
+  //   for (auto .forward.iv = 0; .forward.iv < n; ++.forward.iv) {
+  // auto .reversed.iv = n - .forward.iv - 1;
+  // i = (.reversed.iv + 0) * 1 // LoopHelper.Updates
+  // body(i);   // Body
+  //   }
+  // \endcode
+
+  // Subexpressions with more than one use. One of the constraints of an AST is
+  // that every node object must appear at most once, hence we define a lambda
+  // that creates a new AST node at every use.
+  CaptureVars CopyTransformer(SemaRef);
+  auto MakeNumIterations = [, ]() -> Expr * {
+return AssertSuccess(
+CopyTransformer.TransformExpr(LoopHelper.NumIterations));
+  };
+
+  // Create the iteration variable for the forward loop (from 0 to n-1).
+  VarDecl *ForwardIVDecl =
+  buildVarDecl(SemaRef, {}, IVTy, ForwardIVName, nullptr, OrigVar);
+  auto MakeForwardRef = [ = this->SemaRef, ForwardIVDecl, IVTy,
+ OrigVarLoc]() {
+return buildDeclRefExpr(SemaRef, ForwardIVDecl, IVTy, OrigVarLoc);
+  };
+
+  // Iteration variable for the reversed induction variable (from n-1 downto 
0):
+  // Reuse the iteration variable created by checkOpenMPLoop.
+  auto *ReversedIVDecl = cast(IterationVarRef->getDecl());
+  ReversedIVDecl->setDeclName(
+

[llvm-branch-commits] [clang] [flang] [llvm] [openmp] [Clang][OpenMP] Add reverse and interchange directives (PR #92030)

2024-05-14 Thread Alexey Bataev via llvm-branch-commits


@@ -870,6 +870,106 @@ class OMPSizesClause final
   }
 };
 
+/// This class represents the 'permutation' clause in the
+/// '#pragma omp interchange' directive.
+///
+/// \code{c}
+///   #pragma omp interchange permutation(2,1)
+///   for (int i = 0; i < 64; ++i)
+/// for (int j = 0; j < 64; ++j)
+/// \endcode
+class OMPPermutationClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
+  friend class OMPClauseReader;
+  friend class llvm::TrailingObjects;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Number of arguments in the clause, and hence also the number of loops to
+  /// be permuted.
+  unsigned NumLoops;
+
+  /// Build an empty clause.
+  explicit OMPPermutationClause(int NumLoops)
+  : OMPClause(llvm::omp::OMPC_permutation, SourceLocation(),
+  SourceLocation()),
+NumLoops(NumLoops) {}
+
+public:
+  /// Build a 'permutation' clause AST node.
+  ///
+  /// \param C Context of the AST.
+  /// \param StartLoc  Location of the 'permutation' identifier.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLocLocation of ')'.
+  /// \param Args  Content of the clause.
+  static OMPPermutationClause *
+  Create(const ASTContext , SourceLocation StartLoc, SourceLocation 
LParenLoc,
+ SourceLocation EndLoc, ArrayRef Args);
+
+  /// Build an empty 'permutation' AST node for deserialization.
+  ///
+  /// \param CContext of the AST.
+  /// \param NumLoops Number of arguments in the clause.
+  static OMPPermutationClause *CreateEmpty(const ASTContext ,
+   unsigned NumLoops);
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns the number of list items.
+  unsigned getNumLoops() const { return NumLoops; }
+
+  /// Returns the permutation index expressions.
+  ///@{
+  MutableArrayRef getArgsRefs() {
+return MutableArrayRef(static_cast(this)
+   ->template getTrailingObjects(),
+   NumLoops);
+  }
+  ArrayRef getArgsRefs() const {
+return ArrayRef(static_cast(this)
+->template getTrailingObjects(),
+NumLoops);
+  }
+  ///@}
+
+  /// Sets the permutation index expressions.
+  void setArgRefs(ArrayRef VL) {
+assert(VL.size() == NumLoops);
+std::copy(VL.begin(), VL.end(),
+  static_cast(this)
+  ->template getTrailingObjects());
+  }
+

alexey-bataev wrote:

This should be private

https://github.com/llvm/llvm-project/pull/92030
___
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] [flang] [llvm] [openmp] [Clang][OpenMP] Add reverse and interchange directives (PR #92030)

2024-05-14 Thread Alexey Bataev via llvm-branch-commits


@@ -2146,6 +2146,14 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
+  /** OpenMP reverse directive.
+   */
+  CXCursor_OMPReverseDirective = 307,
+

alexey-bataev wrote:

Split this into 2 patches, one for reverse, one for interchange

https://github.com/llvm/llvm-project/pull/92030
___
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] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)

2024-05-13 Thread Alexey Bataev via llvm-branch-commits


@@ -182,17 +182,34 @@ class OMPLoopScope : public 
CodeGenFunction::RunCleanupsScope {
 }
 return false;
   });
-  PreInits = cast_or_null(LD->getPreInits());
+  PreInits = LD->getPreInits();
 } else if (const auto *Tile = dyn_cast()) {
-  PreInits = cast_or_null(Tile->getPreInits());
+  PreInits = Tile->getPreInits();
 } else if (const auto *Unroll = dyn_cast()) {
-  PreInits = cast_or_null(Unroll->getPreInits());
+  PreInits = Unroll->getPreInits();
 } else {
   llvm_unreachable("Unknown loop-based directive kind.");
 }
 if (PreInits) {
-  for (const auto *I : PreInits->decls())
-CGF.EmitVarDecl(cast(*I));
+  // CompoundStmts and DeclStmts are used as lists of PreInit statements 
and
+  // declarations. Since declarations must be visible in the the following
+  // that they initialize, unpack the ComboundStmt they are nested in.
+  SmallVector PreInitStmts;
+  if (auto *PreInitCompound = dyn_cast(PreInits))

alexey-bataev wrote:

Why need to create coumpound stmt? DeclStmt support multiple declarations 
itself.

https://github.com/llvm/llvm-project/pull/91459
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-09 Thread Alexey Bataev via llvm-branch-commits


@@ -17432,16 +17457,54 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPSizesClause(ArrayRef SizeExprs,
   SourceLocation StartLoc,
   SourceLocation LParenLoc,
   SourceLocation EndLoc) {
-  for (Expr *SizeExpr : SizeExprs) {
-ExprResult NumForLoopsResult = VerifyPositiveIntegerConstantInClause(
-SizeExpr, OMPC_sizes, /*StrictlyPositive=*/true);
-if (!NumForLoopsResult.isUsable())
-  return nullptr;
+  SmallVector SanitizedSizeExprs;
+  llvm::append_range(SanitizedSizeExprs, SizeExprs);
+
+  for (Expr * : SanitizedSizeExprs) {
+// Skip if already sanitized, e.g. during a partial template instantiation.
+if (!SizeExpr)
+  continue;
+
+bool IsValid = isNonNegativeIntegerValue(SizeExpr, SemaRef, OMPC_sizes,
+ /*StrictlyPositive=*/true);
+
+// isNonNegativeIntegerValue returns true for non-integral types (but still
+// emits error diagnostic), so check for the expected type explicitly.
+QualType SizeTy = SizeExpr->getType();
+if (!SizeTy->isIntegerType())
+  IsValid = false;
+
+// Handling in templates is tricky. There are four possibilities to
+// consider:
+//
+// 1a. The expression is valid and we are in a instantiated template or not
+// in a template:
+//   Pass valid expression to be further analysed later in Sema.
+// 1b. The expression is valid and we are in a template (including partial
+// instantiation):
+//   isNonNegativeIntegerValue skipped any checks so there is no
+//   guarantee it will be correct after instantiation.
+//   ActOnOpenMPSizesClause will be called again at instantiation when
+//   it is not in a dependent context anymore. This may cause warnings
+//   to be emitted multiple times.
+// 2a. The expression is invalid and we are in an instantiated template or
+// not in a template:
+//   Invalidate the expression with a clearly wrong value (nullptr) so
+//   later in Sema we do not have to do the same validity analysis 
again
+//   or crash from unexpected data. Error diagnostics have already been
+//   emitted.
+// 2b. The expression is invalid and we are in a template (including 
partial
+// instantiation):
+//   Pass the invalid expression as-is, template instantiation may
+//   replace unexpected types/values with valid ones. The directives
+//   with this clause must not try to use these expressions in 
dependent
+//   contexts.

alexey-bataev wrote:

Sure, delaying is a good approach. If the analysis is delayed till actual 
instantiation, it does not mean that the templates are not handled.

https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-09 Thread Alexey Bataev via llvm-branch-commits


@@ -15197,6 +15202,36 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses,
   // Once the original iteration values are set, append the innermost body.
   Stmt *Inner = Body;
 
+  auto MakeDimTileSize = [ = this->SemaRef, , ,
+  SizesClause, CurScope](int I) -> Expr * {
+Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
+if (isa(DimTileSizeExpr))
+  return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
+
+// When the tile size is not a constant but a variable, it is possible to
+// pass non-positive numbers. To preserve the invariant that every loop

alexey-bataev wrote:

Sure. I'm just saying that it is better to clarify this comment.

https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -15197,6 +15202,36 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses,
   // Once the original iteration values are set, append the innermost body.
   Stmt *Inner = Body;
 
+  auto MakeDimTileSize = [ = this->SemaRef, , ,
+  SizesClause, CurScope](int I) -> Expr * {
+Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
+if (isa(DimTileSizeExpr))
+  return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
+
+// When the tile size is not a constant but a variable, it is possible to
+// pass non-positive numbers. To preserve the invariant that every loop

alexey-bataev wrote:

```suggestion
// pass positive numbers. To preserve the invariant that every loop
```


https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -17432,16 +17457,54 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPSizesClause(ArrayRef SizeExprs,
   SourceLocation StartLoc,
   SourceLocation LParenLoc,
   SourceLocation EndLoc) {
-  for (Expr *SizeExpr : SizeExprs) {
-ExprResult NumForLoopsResult = VerifyPositiveIntegerConstantInClause(
-SizeExpr, OMPC_sizes, /*StrictlyPositive=*/true);
-if (!NumForLoopsResult.isUsable())
-  return nullptr;
+  SmallVector SanitizedSizeExprs;
+  llvm::append_range(SanitizedSizeExprs, SizeExprs);

alexey-bataev wrote:

```suggestion
  SmallVector SanitizedSizeExprs(SizeExprs.begin(), SizeExprs.end());
```


https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -17432,16 +17457,54 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPSizesClause(ArrayRef SizeExprs,
   SourceLocation StartLoc,
   SourceLocation LParenLoc,
   SourceLocation EndLoc) {
-  for (Expr *SizeExpr : SizeExprs) {
-ExprResult NumForLoopsResult = VerifyPositiveIntegerConstantInClause(
-SizeExpr, OMPC_sizes, /*StrictlyPositive=*/true);
-if (!NumForLoopsResult.isUsable())
-  return nullptr;
+  SmallVector SanitizedSizeExprs;
+  llvm::append_range(SanitizedSizeExprs, SizeExprs);
+
+  for (Expr * : SanitizedSizeExprs) {
+// Skip if already sanitized, e.g. during a partial template instantiation.
+if (!SizeExpr)
+  continue;
+
+bool IsValid = isNonNegativeIntegerValue(SizeExpr, SemaRef, OMPC_sizes,
+ /*StrictlyPositive=*/true);
+
+// isNonNegativeIntegerValue returns true for non-integral types (but still
+// emits error diagnostic), so check for the expected type explicitly.
+QualType SizeTy = SizeExpr->getType();
+if (!SizeTy->isIntegerType())
+  IsValid = false;
+
+// Handling in templates is tricky. There are four possibilities to
+// consider:
+//
+// 1a. The expression is valid and we are in a instantiated template or not
+// in a template:
+//   Pass valid expression to be further analysed later in Sema.
+// 1b. The expression is valid and we are in a template (including partial
+// instantiation):
+//   isNonNegativeIntegerValue skipped any checks so there is no
+//   guarantee it will be correct after instantiation.
+//   ActOnOpenMPSizesClause will be called again at instantiation when
+//   it is not in a dependent context anymore. This may cause warnings
+//   to be emitted multiple times.
+// 2a. The expression is invalid and we are in an instantiated template or
+// not in a template:
+//   Invalidate the expression with a clearly wrong value (nullptr) so
+//   later in Sema we do not have to do the same validity analysis 
again
+//   or crash from unexpected data. Error diagnostics have already been
+//   emitted.
+// 2b. The expression is invalid and we are in a template (including 
partial
+// instantiation):
+//   Pass the invalid expression as-is, template instantiation may
+//   replace unexpected types/values with valid ones. The directives
+//   with this clause must not try to use these expressions in 
dependent
+//   contexts.

alexey-bataev wrote:

This must be fixed, even if tricky

https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -15111,13 +15111,11 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses,
   ASTContext  = getASTContext();
   Scope *CurScope = SemaRef.getCurScope();
 
-  auto SizesClauses =
-  OMPExecutableDirective::getClausesOfKind(Clauses);
-  if (SizesClauses.empty()) {
-// A missing 'sizes' clause is already reported by the parser.
+  const OMPSizesClause *SizesClause =

alexey-bataev wrote:

```suggestion
  const auto *SizesClause =
```


https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -15197,6 +15202,36 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses,
   // Once the original iteration values are set, append the innermost body.
   Stmt *Inner = Body;
 
+  auto MakeDimTileSize = [ = this->SemaRef, , ,
+  SizesClause, CurScope](int I) -> Expr * {
+Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
+if (isa(DimTileSizeExpr))
+  return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
+
+// When the tile size is not a constant but a variable, it is possible to
+// pass non-positive numbers. To preserve the invariant that every loop

alexey-bataev wrote:

Or what do you mean here?

https://github.com/llvm/llvm-project/pull/91345
___
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] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-08 Thread Alexey Bataev via llvm-branch-commits


@@ -4991,3 +4971,38 @@ OMPClause 
*Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
   OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc);
   return Actions.OpenMP().ActOnOpenMPVarListClause(Kind, Vars, Locs, Data);
 }
+
+bool Parser::ParseOpenMPExprListClause(OpenMPClauseKind Kind,
+   SourceLocation ,
+   SourceLocation ,
+   SourceLocation ,
+   SmallVectorImpl ,
+   bool ReqIntConst) {
+  assert(getOpenMPClauseName(Kind) == PP.getSpelling(Tok) &&
+ "Expected parsing to start at clause name");
+  ClauseNameLoc = ConsumeToken();
+
+  // Parse inside of '(' and ')'.
+  BalancedDelimiterTracker T(*this, tok::l_paren, 
tok::annot_pragma_openmp_end);
+  if (T.consumeOpen()) {
+Diag(Tok, diag::err_expected) << tok::l_paren;
+return true;
+  }
+
+  // Parse the list with interleaved commas.
+  do {
+ExprResult Val =
+ReqIntConst ? ParseConstantExpression() : ParseAssignmentExpression();
+if (!Val.isUsable()) {
+  // Encountered something other than an expression; abort to ')'.
+  T.skipToEnd();
+  return true;

alexey-bataev wrote:

Do you need to clear output parameters if early exited?

https://github.com/llvm/llvm-project/pull/91345
___
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 [SLP]Fix a crash if the argument of call was affected by minbitwidth analysis (PR #86731)

2024-03-26 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/86731
___
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 [SLP] Fix a crash if the argument of call was affected by minbitwidt analysis (PR #86701)

2024-03-26 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/86701
___
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] Address comments (PR #83854)

2024-03-04 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev closed 
https://github.com/llvm/llvm-project/pull/83854
___
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] Address comments (PR #83854)

2024-03-04 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev created 
https://github.com/llvm/llvm-project/pull/83854

None


___
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] [SLP] Collect candidate VFs in vector in vectorizeStores (NFC). (PR #82793)

2024-02-28 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/82793
___
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] SLP can vectorize frem (PR #82488)

2024-02-22 Thread Alexey Bataev via llvm-branch-commits

alexey-bataev wrote:

> Changing `getArithmeticInstrCost` is just too dangerous. What if one opcode 
> needs TLI for a different reason?

That should be fine, what's the dangerous in it?

https://github.com/llvm/llvm-project/pull/82488
___
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] SLP can vectorize frem (PR #82488)

2024-02-22 Thread Alexey Bataev via llvm-branch-commits

alexey-bataev wrote:

> Personally I'm happy with keeping this nuance outside of TTI but if we really 
> want this captured within TTI then I think it's time to break FREM into its 
> own cost function (i.e. implement getFRemInstrCost. That way 
> getArithmeticInstrCost can work as it does today and the new function can be 
> documented to highlight it's assumption that if a TLI is passed in and a 
> vector mapping is present then the return value is only valid based on it's 
> assumption that vector FREM instructions will be transformed by a following 
> transformation pass. I prefer this to say, adding TLI to 
> getArithmeticInstrCost, because I'd rather users of getFRemInstrCost to 
> explicitly enter into this contract.

Hm, not sure adding getFRemInstrCost is the best solution here. I would more 
support adding TLI to getArithmeticInstrCost instead. Some other users may 
benefit from this too. Though getFRemInstrCost is still better than the current 
solution

https://github.com/llvm/llvm-project/pull/82488
___
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] SLP can vectorize frem (PR #82488)

2024-02-22 Thread Alexey Bataev via llvm-branch-commits


@@ -869,6 +870,18 @@ TargetTransformInfo::getOperandInfo(const Value *V) {
   return {OpInfo, OpProps};
 }
 
+InstructionCost TargetTransformInfo::getVecLibCallCost(
+const int OpCode, const TargetLibraryInfo *TLI, VectorType *VecTy,
+TTI::TargetCostKind CostKind) {
+  Type *ScalarTy = VecTy->getScalarType();
+  LibFunc Func;
+  if (TLI->getLibFunc(OpCode, ScalarTy, Func) &&
+  TLI->isFunctionVectorizable(TLI->getName(Func), 
VecTy->getElementCount()))

alexey-bataev wrote:

Yes, and what I'm saying that TTI should handle this since this is 
target-specific lowering.
If you don't want to propagate TLI, then just copy the legality checks from TLI 
to TTI and the cost estimation for this specific lowering to the 
getArithmeticInstructionCost function. This is what we usually do in similar 
cases for other targets.

https://github.com/llvm/llvm-project/pull/82488
___
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] SLP can vectorize frem (PR #82488)

2024-02-22 Thread Alexey Bataev via llvm-branch-commits


@@ -869,6 +870,18 @@ TargetTransformInfo::getOperandInfo(const Value *V) {
   return {OpInfo, OpProps};
 }
 
+InstructionCost TargetTransformInfo::getVecLibCallCost(
+const int OpCode, const TargetLibraryInfo *TLI, VectorType *VecTy,
+TTI::TargetCostKind CostKind) {
+  Type *ScalarTy = VecTy->getScalarType();
+  LibFunc Func;
+  if (TLI->getLibFunc(OpCode, ScalarTy, Func) &&
+  TLI->isFunctionVectorizable(TLI->getName(Func), 
VecTy->getElementCount()))

alexey-bataev wrote:

It does not known what transsformation is doing, it does exactly what you said 
- estimates the cost of the target-specific code. WE're not emitting frem calls 
directly, we're still emitting regular frem vector code, which is then lowered 
specifically for ARM. And target specific TTI should be aware of this.

https://github.com/llvm/llvm-project/pull/82488
___
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] SLP can vectorize frem (PR #82488)

2024-02-22 Thread Alexey Bataev via llvm-branch-commits


@@ -869,6 +870,18 @@ TargetTransformInfo::getOperandInfo(const Value *V) {
   return {OpInfo, OpProps};
 }
 
+InstructionCost TargetTransformInfo::getVecLibCallCost(
+const int OpCode, const TargetLibraryInfo *TLI, VectorType *VecTy,
+TTI::TargetCostKind CostKind) {
+  Type *ScalarTy = VecTy->getScalarType();
+  LibFunc Func;
+  if (TLI->getLibFunc(OpCode, ScalarTy, Func) &&
+  TLI->isFunctionVectorizable(TLI->getName(Func), 
VecTy->getElementCount()))

alexey-bataev wrote:

I disagree with this approach and still insist that it should be implemented in 
TTI rather doing some target specific "magic" in the vectorizers

https://github.com/llvm/llvm-project/pull/82488
___
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] SLP can vectorize frem (PR #82488)

2024-02-21 Thread Alexey Bataev via llvm-branch-commits


@@ -8362,9 +8362,20 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef VectorizedVals,
   unsigned OpIdx = isa(VL0) ? 0 : 1;
   TTI::OperandValueInfo Op1Info = getOperandInfo(E->getOperand(0));
   TTI::OperandValueInfo Op2Info = getOperandInfo(E->getOperand(OpIdx));
-  return TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind, Op1Info,
- Op2Info) +
- CommonCost;
+  auto VecCost = TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind,
+ Op1Info, Op2Info);
+  // Some targets can replace frem with vector library calls.
+  if (ShuffleOrOp == Instruction::FRem) {
+LibFunc Func;
+if (TLI->getLibFunc(ShuffleOrOp, ScalarTy, Func) &&
+TLI->isFunctionVectorizable(TLI->getName(Func),
+VecTy->getElementCount())) {

alexey-bataev wrote:

Better to teach TTI about TLI rather than do something like this in SLP. SLP 
should keep its target independent nature, all that target-specific stuff 
should live in TTI

https://github.com/llvm/llvm-project/pull/82488
___
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: [SLP]Fix PR79229: Check that extractelement is used only in a single node (PR #81984)

2024-02-16 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/81984
___
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] [VPlan] Model address separately. (PR #72164)

2023-11-14 Thread Alexey Bataev via llvm-branch-commits


@@ -8231,13 +8231,24 @@ VPRecipeBase 
*VPRecipeBuilder::tryToWidenMemory(Instruction *I,
   bool Consecutive =
   Reverse || Decision == LoopVectorizationCostModel::CM_Widen;
 
+  VPValue *Ptr = isa(I) ? Operands[0] : Operands[1];
+  if (Decision != LoopVectorizationCostModel::CM_GatherScatter &&
+  Decision != LoopVectorizationCostModel::CM_Interleave) {
+auto *VectorPtr = Reverse
+  ? new VPInstruction(VPInstruction::CreateVectorPtr,
+  {Ptr, Ptr}, I->getDebugLoc())
+  : new VPInstruction(VPInstruction::CreateVectorPtr,

alexey-bataev wrote:

Just VectorPtr maybe?

https://github.com/llvm/llvm-project/pull/72164
___
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] [VPlan] Model address separately. (PR #72164)

2023-11-14 Thread Alexey Bataev via llvm-branch-commits


@@ -404,6 +405,49 @@ Value *VPInstruction::generateInstruction(VPTransformState 
,
 Builder.GetInsertBlock()->getTerminator()->eraseFromParent();
 return CondBr;
   }
+  case VPInstruction::CreateVectorPtr: {
+// Calculate the pointer for the specific unroll-part.
+Value *PartPtr = nullptr;
+bool IsReverse = getNumOperands() > 1;
+auto *MemR = cast(*user_begin());
+Type *ScalarDataTy =
+MemR->isStore() ? cast(>getIngredient())
+  ->getValueOperand()
+  ->getType()
+: cast(>getIngredient())->getType();
+// Use i32 for the gep index type when the value is constant,
+// or query DataLayout for a more suitable index type otherwise.
+const DataLayout  =
+Builder.GetInsertBlock()->getModule()->getDataLayout();
+Type *IndexTy = State.VF.isScalable() && (IsReverse || Part > 0)
+? DL.getIndexType(ScalarDataTy->getPointerTo())
+: Builder.getInt32Ty();
+Value *Ptr = State.get(getOperand(0), VPIteration(0, 0));
+bool InBounds = false;
+if (auto *gep = dyn_cast(Ptr->stripPointerCasts()))

alexey-bataev wrote:

Gep

https://github.com/llvm/llvm-project/pull/72164
___
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] [VPlan] Model address separately. (PR #72164)

2023-11-14 Thread Alexey Bataev via llvm-branch-commits


@@ -8231,13 +8231,24 @@ VPRecipeBase 
*VPRecipeBuilder::tryToWidenMemory(Instruction *I,
   bool Consecutive =
   Reverse || Decision == LoopVectorizationCostModel::CM_Widen;
 
+  VPValue *Ptr = isa(I) ? Operands[0] : Operands[1];
+  if (Decision != LoopVectorizationCostModel::CM_GatherScatter &&
+  Decision != LoopVectorizationCostModel::CM_Interleave) {
+auto *VectorPtr = Reverse
+  ? new VPInstruction(VPInstruction::CreateVectorPtr,
+  {Ptr, Ptr}, I->getDebugLoc())

alexey-bataev wrote:

I think better to add some kind of bool flag for reverse rather than mimic it 
with unused operand. Can you make it?

https://github.com/llvm/llvm-project/pull/72164
___
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] b272698 - [OPENMP]Do not use OMP_MAP_TARGET_PARAM for data movement directives.

2021-01-19 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2021-01-19T12:41:15-08:00
New Revision: b272698de790d6603db7992c0c0ad6446b7a52b8

URL: 
https://github.com/llvm/llvm-project/commit/b272698de790d6603db7992c0c0ad6446b7a52b8
DIFF: 
https://github.com/llvm/llvm-project/commit/b272698de790d6603db7992c0c0ad6446b7a52b8.diff

LOG: [OPENMP]Do not use OMP_MAP_TARGET_PARAM for data movement directives.

OMP_MAP_TARGET_PARAM flag is used to mark the data that shoud be passed
as arguments to the target kernels, nothing else. But the compiler still
marks the data with OMP_MAP_TARGET_PARAM flags even if the data is
passed to the data movement directives, like target data, target update
etc. This flag is just ignored for this directives and the compiler does
not need to emit it.

Reviewed By: cchen

Differential Revision: https://reviews.llvm.org/D91261

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_mapper_codegen.cpp
clang/test/OpenMP/target_data_codegen.cpp
clang/test/OpenMP/target_data_map_pointer_array_subscript_codegen.cpp
clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
clang/test/OpenMP/target_data_use_device_ptr_if_codegen.cpp
clang/test/OpenMP/target_enter_data_codegen.cpp
clang/test/OpenMP/target_enter_data_depend_codegen.cpp
clang/test/OpenMP/target_exit_data_codegen.cpp
clang/test/OpenMP/target_exit_data_depend_codegen.cpp
clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
clang/test/OpenMP/target_update_codegen.cpp
clang/test/OpenMP/target_update_depend_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 17fa56fb06c8..22df862db1b5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8233,7 +8233,7 @@ class MappableExprsHandler {
  MapFlagsArrayTy ,
  const StructRangeInfoTy ,
  const ValueDecl *VD = nullptr,
- bool NotTargetParams = false) const {
+ bool NotTargetParams = true) const {
 if (CurTypes.size() == 1 &&
 ((CurTypes.back() & OMP_MAP_MEMBER_OF) != OMP_MAP_MEMBER_OF) &&
 !PartialStruct.IsArraySection)
@@ -8284,7 +8284,7 @@ class MappableExprsHandler {
   /// pair of the relevant declaration and index where it occurs is appended to
   /// the device pointers info array.
   void generateAllInfo(
-  MapCombinedInfoTy , bool NotTargetParams = false,
+  MapCombinedInfoTy ,
   const llvm::DenseSet>  =
   llvm::DenseSet>()) const {
 // We have to process the component lists that relate with the same
@@ -8420,9 +8420,7 @@ class MappableExprsHandler {
   UseDevicePtrCombinedInfo.Pointers.push_back(Ptr);
   UseDevicePtrCombinedInfo.Sizes.push_back(
   llvm::Constant::getNullValue(CGF.Int64Ty));
-  UseDevicePtrCombinedInfo.Types.push_back(
-  OMP_MAP_RETURN_PARAM |
-  (NotTargetParams ? OMP_MAP_NONE : OMP_MAP_TARGET_PARAM));
+  UseDevicePtrCombinedInfo.Types.push_back(OMP_MAP_RETURN_PARAM);
   UseDevicePtrCombinedInfo.Mappers.push_back(nullptr);
 }
   }
@@ -8490,19 +8488,13 @@ class MappableExprsHandler {
   CombinedInfo.Pointers.push_back(Ptr);
   CombinedInfo.Sizes.push_back(
   llvm::Constant::getNullValue(CGF.Int64Ty));
-  CombinedInfo.Types.push_back(
-  OMP_MAP_RETURN_PARAM |
-  (NotTargetParams ? OMP_MAP_NONE : OMP_MAP_TARGET_PARAM));
+  CombinedInfo.Types.push_back(OMP_MAP_RETURN_PARAM);
   CombinedInfo.Mappers.push_back(nullptr);
 }
   }
 }
 
 for (const auto  : Info) {
-  // We need to know when we generate information for the first component
-  // associated with a capture, because the mapping flags depend on it.
-  bool IsFirstComponentList = !NotTargetParams;
-
   // Underlying variable declaration used in the map clause.
   const ValueDecl *VD = std::get<0>(M);
 
@@ -8520,8 +8512,8 @@ class MappableExprsHandler {
 L.Components.back().isNonContiguous();
 generateInfoForComponentList(
 L.MapType, L.MapModifiers, L.MotionModifiers, L.Components, 
CurInfo,
-PartialStruct, IsFirstComponentList, L.IsImplicit, L.Mapper,
-L.ForDeviceAddr, VD, L.VarRef);
+PartialStruct, /*IsFirstComponentList=*/false, L.IsImplicit,
+L.Mapper, L.ForDeviceAddr, VD, L.VarRef);
 
 // If this entry relates with a device pointer, set the relevant
 // declaration and add the 'return pointer' flag.
@@ -8538,7 +8530,6 @@ class MappableExprsHandler {
   RelevantVD);
   

[llvm-branch-commits] [llvm] e463bd5 - Revert "[SLP]Merge reorder and reuse shuffles."

2021-01-19 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2021-01-19T11:48:04-08:00
New Revision: e463bd53c03ff9183bd30030477dfe6f3b2fdd0c

URL: 
https://github.com/llvm/llvm-project/commit/e463bd53c03ff9183bd30030477dfe6f3b2fdd0c
DIFF: 
https://github.com/llvm/llvm-project/commit/e463bd53c03ff9183bd30030477dfe6f3b2fdd0c.diff

LOG: Revert "[SLP]Merge reorder and reuse shuffles."

This reverts commit 438682de6a38ac97f89fa38faf5c8dc9b09cd9ad to fix the
bug with the reducing size of the resulting vector for the entry node
with multiple users.

Added: 


Modified: 
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll
llvm/test/Transforms/SLPVectorizer/X86/PR32086.ll
llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp 
b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 0fee52dcdd93..24885e4d8257 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3500,7 +3500,6 @@ InstructionCost BoUpSLP::getEntryCost(TreeEntry *E) {
 
 case Instruction::ExtractValue:
 case Instruction::ExtractElement: {
-  InstructionCost DeadCost = 0;
   if (NeedToShuffleReuses) {
 unsigned Idx = 0;
 for (unsigned I : E->ReuseShuffleIndices) {
@@ -3528,10 +3527,12 @@ InstructionCost BoUpSLP::getEntryCost(TreeEntry *E) {
   ReuseShuffleCost +=
   TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, Idx);
 }
-DeadCost = ReuseShuffleCost;
-  } else if (!E->ReorderIndices.empty()) {
-DeadCost = 
TTI->getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc,
-   VecTy);
+  }
+  InstructionCost DeadCost = ReuseShuffleCost;
+  if (!E->ReorderIndices.empty()) {
+// TODO: Merge this shuffle with the ReuseShuffleCost.
+DeadCost += TTI->getShuffleCost(
+TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
   }
   for (unsigned I = 0, E = VL.size(); I < E; ++I) {
 Instruction *EI = cast(VL[I]);
@@ -3755,9 +3756,11 @@ InstructionCost BoUpSLP::getEntryCost(TreeEntry *E) {
 Instruction::Load, VecTy, cast(VL0)->getPointerOperand(),
 /*VariableMask=*/false, alignment, CostKind, VL0);
   }
-  if (!NeedToShuffleReuses && !E->ReorderIndices.empty())
+  if (!E->ReorderIndices.empty()) {
+// TODO: Merge this shuffle with the ReuseShuffleCost.
 VecLdCost += TTI->getShuffleCost(
 TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
+  }
   LLVM_DEBUG(dumpTreeCosts(E, ReuseShuffleCost, VecLdCost, ScalarLdCost));
   return ReuseShuffleCost + VecLdCost - ScalarLdCost;
 }
@@ -3769,14 +3772,18 @@ InstructionCost BoUpSLP::getEntryCost(TreeEntry *E) {
   Align Alignment = SI->getAlign();
   InstructionCost ScalarEltCost = TTI->getMemoryOpCost(
   Instruction::Store, ScalarTy, Alignment, 0, CostKind, VL0);
+  if (NeedToShuffleReuses)
+ReuseShuffleCost = -(ReuseShuffleNumbers - VL.size()) * ScalarEltCost;
   InstructionCost ScalarStCost = VecTy->getNumElements() * ScalarEltCost;
   InstructionCost VecStCost = TTI->getMemoryOpCost(
   Instruction::Store, VecTy, Alignment, 0, CostKind, VL0);
-  if (IsReorder)
+  if (IsReorder) {
+// TODO: Merge this shuffle with the ReuseShuffleCost.
 VecStCost += TTI->getShuffleCost(
 TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
+  }
   LLVM_DEBUG(dumpTreeCosts(E, ReuseShuffleCost, VecStCost, ScalarStCost));
-  return VecStCost - ScalarStCost;
+  return ReuseShuffleCost + VecStCost - ScalarStCost;
 }
 case Instruction::Call: {
   CallInst *CI = cast(VL0);
@@ -4323,64 +4330,6 @@ Value *BoUpSLP::vectorizeTree(ArrayRef VL) {
   return Vec;
 }
 
-namespace {
-/// Merges shuffle masks and emits final shuffle instruction, if required.
-class ShuffleInstructionBuilder {
-  IRBuilderBase 
-  bool IsFinalized = false;
-  SmallVector Mask;
-
-public:
-  ShuffleInstructionBuilder(IRBuilderBase ) : Builder(Builder) {}
-
-  /// Adds a mask, inverting it before applying.
-  void addInversedMask(ArrayRef SubMask) {
-if (SubMask.empty())
-  return;
-SmallVector NewMask;
-inversePermutation(SubMask, NewMask);
-addMask(NewMask);
-  }
-
-  /// Functions adds masks, merging them into  single one.
-  void addMask(ArrayRef SubMask) {
-SmallVector NewMask(SubMask.begin(), SubMask.end());
-addMask(NewMask);
-  }
-
-  void addMask(ArrayRef SubMask) {
-if (SubMask.empty())
-  return;
-if (Mask.empty()) {
-  Mask.append(SubMask.begin(), SubMask.end());
-  return;
-}
-SmallVector NewMask(SubMask.size(), SubMask.size());
-int TermValue = std::min(Mask.size(), 

[llvm-branch-commits] [llvm] 0e57084 - [SLP][NFC]Add a test for reused shrink check, NFC.

2021-01-08 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2021-01-08T06:23:23-08:00
New Revision: 0e57084d0efaab215d67c81a4664e1ee0622d3f1

URL: 
https://github.com/llvm/llvm-project/commit/0e57084d0efaab215d67c81a4664e1ee0622d3f1
DIFF: 
https://github.com/llvm/llvm-project/commit/0e57084d0efaab215d67c81a4664e1ee0622d3f1.diff

LOG: [SLP][NFC]Add a test for reused shrink check, NFC.

Added: 


Modified: 
llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll

Removed: 




diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll 
b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
index 110e114b..1b89c9a437a2 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
@@ -59,3 +59,49 @@ bb:
   store i32 %tmp45, i32* %tmp46, align 4
   ret void
 }
+
+define internal i32 @ipvideo_decode_block_opcode_0xD_16() {
+; CHECK-LABEL: @ipvideo_decode_block_opcode_0xD_16(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br label [[FOR_BODY:%.*]]
+; CHECK:   for.body:
+; CHECK-NEXT:[[TMP0:%.*]] = phi <2 x i16> [ undef, [[ENTRY:%.*]] ], [ 
[[TMP0]], [[IF_END:%.*]] ]
+; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x i16> 
poison, <8 x i32> 
+; CHECK-NEXT:br label [[IF_END]]
+; CHECK:   if.end:
+; CHECK-NEXT:[[ARRAYIDX11_1:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 1
+; CHECK-NEXT:[[ARRAYIDX11_2:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 2
+; CHECK-NEXT:[[ARRAYIDX11_3:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 3
+; CHECK-NEXT:[[ARRAYIDX11_4:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 4
+; CHECK-NEXT:[[ARRAYIDX11_5:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 5
+; CHECK-NEXT:[[ARRAYIDX11_6:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 6
+; CHECK-NEXT:[[ARRAYIDX11_7:%.*]] = getelementptr inbounds i16, i16* 
undef, i32 7
+; CHECK-NEXT:store <8 x i16> [[SHUFFLE]], <8 x i16>* undef, align 2
+; CHECK-NEXT:br label [[FOR_BODY]]
+;
+entry:
+  br label %for.body
+
+for.body: ; preds = %if.end, %entry
+  %P.sroa.7.0 = phi i16 [ undef, %entry ], [ %P.sroa.7.0, %if.end ]
+  %P.sroa.0.0 = phi i16 [ undef, %entry ], [ %P.sroa.0.0, %if.end ]
+  br label %if.end
+
+if.end:   ; preds = %for.body
+  store i16 %P.sroa.0.0, i16* undef, align 2
+  %arrayidx11.1 = getelementptr inbounds i16, i16* undef, i32 1
+  store i16 %P.sroa.0.0, i16* %arrayidx11.1, align 2
+  %arrayidx11.2 = getelementptr inbounds i16, i16* undef, i32 2
+  store i16 %P.sroa.0.0, i16* %arrayidx11.2, align 2
+  %arrayidx11.3 = getelementptr inbounds i16, i16* undef, i32 3
+  store i16 %P.sroa.0.0, i16* %arrayidx11.3, align 2
+  %arrayidx11.4 = getelementptr inbounds i16, i16* undef, i32 4
+  store i16 %P.sroa.7.0, i16* %arrayidx11.4, align 2
+  %arrayidx11.5 = getelementptr inbounds i16, i16* undef, i32 5
+  store i16 %P.sroa.7.0, i16* %arrayidx11.5, align 2
+  %arrayidx11.6 = getelementptr inbounds i16, i16* undef, i32 6
+  store i16 %P.sroa.7.0, i16* %arrayidx11.6, align 2
+  %arrayidx11.7 = getelementptr inbounds i16, i16* undef, i32 7
+  store i16 %P.sroa.7.0, i16* %arrayidx11.7, align 2
+  br label %for.body
+}



___
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] 4284afd - [SLP]Need shrink the load vector after reordering.

2021-01-07 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2021-01-07T04:50:48-08:00
New Revision: 4284afdf9432f7d756f56b0ab21d69191adefa8d

URL: 
https://github.com/llvm/llvm-project/commit/4284afdf9432f7d756f56b0ab21d69191adefa8d
DIFF: 
https://github.com/llvm/llvm-project/commit/4284afdf9432f7d756f56b0ab21d69191adefa8d.diff

LOG: [SLP]Need shrink the load vector after reordering.

After merging the shuffles, we cannot rely on the previous shuffle
anymore and need to shrink the final shuffle, if it is required.

Reported in D92668

Differential Revision: https://reviews.llvm.org/D93967

Added: 


Modified: 
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp 
b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index abd0470270d5..8d6453f277ea 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4260,18 +4260,13 @@ Value *BoUpSLP::vectorizeTree(ArrayRef VL) {
   if (E->isSame(VL)) {
 Value *V = vectorizeTree(E);
 if (VL.size() == E->Scalars.size() && !E->ReuseShuffleIndices.empty()) 
{
-  // We need to get the vectorized value but without shuffle.
-  if (auto *SV = dyn_cast(V)) {
-V = SV->getOperand(0);
-  } else {
-// Reshuffle to get only unique values.
-SmallVector UniqueIdxs;
-SmallSet UsedIdxs;
-for (int Idx : E->ReuseShuffleIndices)
-  if (UsedIdxs.insert(Idx).second)
-UniqueIdxs.emplace_back(Idx);
-V = Builder.CreateShuffleVector(V, UniqueIdxs);
-  }
+  // Reshuffle to get only unique values.
+  SmallVector UniqueIdxs;
+  SmallSet UsedIdxs;
+  for (int Idx : E->ReuseShuffleIndices)
+if (UsedIdxs.insert(Idx).second)
+  UniqueIdxs.emplace_back(Idx);
+  V = Builder.CreateShuffleVector(V, UniqueIdxs, "shrink.shuffle");
 }
 return V;
   }

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll 
b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
index 110e114b..533b48eec295 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
@@ -10,7 +10,8 @@ define void @wombat(i32* %ptr, i32* %ptr1) {
 ; CHECK-NEXT:[[TMP1:%.*]] = load <2 x i32>, <2 x i32>* [[TMP0]], align 8
 ; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> 
poison, <4 x i32> 
 ; CHECK-NEXT:[[TMP27:%.*]] = getelementptr inbounds i32, i32* 
[[PTR1:%.*]], i32 3
-; CHECK-NEXT:[[TMP2:%.*]] = add nsw <2 x i32> [[TMP1]], 
+; CHECK-NEXT:[[SHRINK_SHUFFLE:%.*]] = shufflevector <4 x i32> [[SHUFFLE]], 
<4 x i32> poison, <2 x i32> 
+; CHECK-NEXT:[[TMP2:%.*]] = add nsw <2 x i32> [[SHRINK_SHUFFLE]], 
 ; CHECK-NEXT:[[SHUFFLE1:%.*]] = shufflevector <2 x i32> [[TMP2]], <2 x 
i32> poison, <4 x i32> 
 ; CHECK-NEXT:[[TMP34:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], 
i32 4
 ; CHECK-NEXT:[[TMP40:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], 
i32 5



___
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] bf2a78f - [SLP]Add a test for correct use of the reordered loads, NFC.

2021-01-01 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2021-01-01T08:27:59-08:00
New Revision: bf2a78fd4ae90e6d427cb6abe64108a047c90c05

URL: 
https://github.com/llvm/llvm-project/commit/bf2a78fd4ae90e6d427cb6abe64108a047c90c05
DIFF: 
https://github.com/llvm/llvm-project/commit/bf2a78fd4ae90e6d427cb6abe64108a047c90c05.diff

LOG: [SLP]Add a test for correct use of the reordered loads, NFC.

Added: 
llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll

Modified: 


Removed: 




diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll 
b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
new file mode 100644
index ..110e114b
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
@@ -0,0 +1,61 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -slp-vectorizer -S -o - -mtriple=x86_64-unknown-linux-gnu 
-mcpu=haswell < %s | FileCheck %s
+
+define void @wombat(i32* %ptr, i32* %ptr1) {
+; CHECK-LABEL: @wombat(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:[[TMP7:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], 
i64 1
+; CHECK-NEXT:[[TMP8:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 0
+; CHECK-NEXT:[[TMP0:%.*]] = bitcast i32* [[TMP8]] to <2 x i32>*
+; CHECK-NEXT:[[TMP1:%.*]] = load <2 x i32>, <2 x i32>* [[TMP0]], align 8
+; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> 
poison, <4 x i32> 
+; CHECK-NEXT:[[TMP27:%.*]] = getelementptr inbounds i32, i32* 
[[PTR1:%.*]], i32 3
+; CHECK-NEXT:[[TMP2:%.*]] = add nsw <2 x i32> [[TMP1]], 
+; CHECK-NEXT:[[SHUFFLE1:%.*]] = shufflevector <2 x i32> [[TMP2]], <2 x 
i32> poison, <4 x i32> 
+; CHECK-NEXT:[[TMP34:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], 
i32 4
+; CHECK-NEXT:[[TMP40:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], 
i32 5
+; CHECK-NEXT:[[TMP3:%.*]] = icmp sgt <4 x i32> [[SHUFFLE]], undef
+; CHECK-NEXT:[[TMP4:%.*]] = select <4 x i1> [[TMP3]], <4 x i32> undef, <4 
x i32> [[SHUFFLE1]]
+; CHECK-NEXT:[[TMP5:%.*]] = select <4 x i1> zeroinitializer, <4 x i32> 
zeroinitializer, <4 x i32> [[TMP4]]
+; CHECK-NEXT:[[TMP46:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], 
i32 6
+; CHECK-NEXT:[[TMP6:%.*]] = bitcast i32* [[TMP27]] to <4 x i32>*
+; CHECK-NEXT:store <4 x i32> [[TMP5]], <4 x i32>* [[TMP6]], align 8
+; CHECK-NEXT:ret void
+;
+bb:
+  %tmp7 = getelementptr inbounds i32, i32* %ptr, i64 1
+  %tmp8 = getelementptr inbounds i32, i32* %ptr, i64 0
+  %tmp12 = load i32, i32* %tmp7, align 4
+  %tmp13 = load i32, i32* %tmp8, align 8
+  %tmp21 = add nsw i32 %tmp12, -1
+  %tmp22 = fptosi float undef to i32
+  %tmp23 = icmp slt i32 %tmp22, 0
+  %tmp24 = icmp sgt i32 %tmp12, %tmp22
+  %tmp25 = select i1 %tmp24, i32 %tmp22, i32 %tmp21
+  %tmp26 = select i1 %tmp23, i32 0, i32 %tmp25
+  %tmp27 = getelementptr inbounds i32, i32* %ptr1, i32 3
+  store i32 %tmp26, i32* %tmp27, align 8
+  %tmp28 = add nsw i32 %tmp13, -1
+  %tmp29 = fptosi float undef to i32
+  %tmp30 = icmp slt i32 %tmp29, 0
+  %tmp31 = icmp sgt i32 %tmp13, %tmp29
+  %tmp32 = select i1 %tmp31, i32 %tmp29, i32 %tmp28
+  %tmp33 = select i1 %tmp30, i32 0, i32 %tmp32
+  %tmp34 = getelementptr inbounds i32, i32* %ptr1, i32 4
+  store i32 %tmp33, i32* %tmp34, align 4
+  %tmp35 = fptosi float undef to i32
+  %tmp36 = icmp slt i32 %tmp35, 0
+  %tmp37 = icmp sgt i32 %tmp12, %tmp35
+  %tmp38 = select i1 %tmp37, i32 %tmp35, i32 %tmp21
+  %tmp39 = select i1 %tmp36, i32 0, i32 %tmp38
+  %tmp40 = getelementptr inbounds i32, i32* %ptr1, i32 5
+  store i32 %tmp39, i32* %tmp40, align 8
+  %tmp41 = fptosi float undef to i32
+  %tmp42 = icmp slt i32 %tmp41, 0
+  %tmp43 = icmp sgt i32 %tmp13, %tmp41
+  %tmp44 = select i1 %tmp43, i32 %tmp41, i32 %tmp28
+  %tmp45 = select i1 %tmp42, i32 0, i32 %tmp44
+  %tmp46 = getelementptr inbounds i32, i32* %ptr1, i32 6
+  store i32 %tmp45, i32* %tmp46, align 4
+  ret void
+}



___
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] 438682d - [SLP]Merge reorder and reuse shuffles.

2020-12-07 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2020-12-07T07:50:00-08:00
New Revision: 438682de6a38ac97f89fa38faf5c8dc9b09cd9ad

URL: 
https://github.com/llvm/llvm-project/commit/438682de6a38ac97f89fa38faf5c8dc9b09cd9ad
DIFF: 
https://github.com/llvm/llvm-project/commit/438682de6a38ac97f89fa38faf5c8dc9b09cd9ad.diff

LOG: [SLP]Merge reorder and reuse shuffles.

It is possible to merge reuse and reorder shuffles and reduce the total
cost of the ivectorization tree/number of final instructions.

Differential Revision: https://reviews.llvm.org/D92668

Added: 


Modified: 
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll
llvm/test/Transforms/SLPVectorizer/X86/PR32086.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp 
b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 66d736974fbc..f78a4d9d9c71 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3480,6 +3480,7 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
 
 case Instruction::ExtractValue:
 case Instruction::ExtractElement: {
+  int DeadCost = 0;
   if (NeedToShuffleReuses) {
 unsigned Idx = 0;
 for (unsigned I : E->ReuseShuffleIndices) {
@@ -3507,12 +3508,10 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
   ReuseShuffleCost +=
   TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, Idx);
 }
-  }
-  int DeadCost = ReuseShuffleCost;
-  if (!E->ReorderIndices.empty()) {
-// TODO: Merge this shuffle with the ReuseShuffleCost.
-DeadCost += TTI->getShuffleCost(
-TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
+DeadCost = ReuseShuffleCost;
+  } else if (!E->ReorderIndices.empty()) {
+DeadCost = 
TTI->getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc,
+   VecTy);
   }
   for (unsigned I = 0, E = VL.size(); I < E; ++I) {
 Instruction *EI = cast(VL[I]);
@@ -3738,11 +3737,9 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
 Instruction::Load, VecTy, cast(VL0)->getPointerOperand(),
 /*VariableMask=*/false, alignment, CostKind, VL0);
   }
-  if (!E->ReorderIndices.empty()) {
-// TODO: Merge this shuffle with the ReuseShuffleCost.
+  if (!NeedToShuffleReuses && !E->ReorderIndices.empty())
 VecLdCost += TTI->getShuffleCost(
 TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
-  }
   LLVM_DEBUG(dumpTreeCosts(E, ReuseShuffleCost, VecLdCost, ScalarLdCost));
   return ReuseShuffleCost + VecLdCost - ScalarLdCost;
 }
@@ -3755,18 +3752,14 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
   int ScalarEltCost =
   TTI->getMemoryOpCost(Instruction::Store, ScalarTy, Alignment, 0,
CostKind, VL0);
-  if (NeedToShuffleReuses)
-ReuseShuffleCost = -(ReuseShuffleNumbers - VL.size()) * ScalarEltCost;
   int ScalarStCost = VecTy->getNumElements() * ScalarEltCost;
   int VecStCost = TTI->getMemoryOpCost(Instruction::Store,
VecTy, Alignment, 0, CostKind, VL0);
-  if (IsReorder) {
-// TODO: Merge this shuffle with the ReuseShuffleCost.
+  if (IsReorder)
 VecStCost += TTI->getShuffleCost(
 TargetTransformInfo::SK_PermuteSingleSrc, VecTy);
-  }
   LLVM_DEBUG(dumpTreeCosts(E, ReuseShuffleCost, VecStCost, ScalarStCost));
-  return ReuseShuffleCost + VecStCost - ScalarStCost;
+  return VecStCost - ScalarStCost;
 }
 case Instruction::Call: {
   CallInst *CI = cast(VL0);
@@ -4310,6 +4303,64 @@ Value *BoUpSLP::vectorizeTree(ArrayRef VL) {
   return Vec;
 }
 
+namespace {
+/// Merges shuffle masks and emits final shuffle instruction, if required.
+class ShuffleInstructionBuilder {
+  IRBuilderBase 
+  bool IsFinalized = false;
+  SmallVector Mask;
+
+public:
+  ShuffleInstructionBuilder(IRBuilderBase ) : Builder(Builder) {}
+
+  /// Adds a mask, inverting it before applying.
+  void addInversedMask(ArrayRef SubMask) {
+if (SubMask.empty())
+  return;
+SmallVector NewMask;
+inversePermutation(SubMask, NewMask);
+addMask(NewMask);
+  }
+
+  /// Functions adds masks, merging them into  single one.
+  void addMask(ArrayRef SubMask) {
+SmallVector NewMask(SubMask.begin(), SubMask.end());
+addMask(NewMask);
+  }
+
+  void addMask(ArrayRef SubMask) {
+if (SubMask.empty())
+  return;
+if (Mask.empty()) {
+  Mask.append(SubMask.begin(), SubMask.end());
+  return;
+}
+SmallVector NewMask(SubMask.size(), SubMask.size());
+int TermValue = std::min(Mask.size(), SubMask.size());
+for (int I = 0, E = SubMask.size(); I < E; ++I) {
+  if (SubMask[I] >= TermValue || Mask[SubMask[I]] >= TermValue) {
+   

[llvm-branch-commits] [llvm] 97c08db - [SLP]Update test checks, NFC.

2020-12-07 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2020-12-07T06:12:05-08:00
New Revision: 97c08db84e3a7eb4eba1eab2678f6f68c2afaca3

URL: 
https://github.com/llvm/llvm-project/commit/97c08db84e3a7eb4eba1eab2678f6f68c2afaca3
DIFF: 
https://github.com/llvm/llvm-project/commit/97c08db84e3a7eb4eba1eab2678f6f68c2afaca3.diff

LOG: [SLP]Update test checks, NFC.

Added: 


Modified: 
llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll

Removed: 




diff  --git a/llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll 
b/llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll
index 1a981a32804b..16e5da0a7e43 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/PR38339.ll
@@ -9,7 +9,7 @@ define void @f1(<2 x i16> %x, i16* %a) {
 ; CHECK-NEXT:[[PTR2:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 2
 ; CHECK-NEXT:[[PTR3:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 3
 ; CHECK-NEXT:[[TMP1:%.*]] = extractelement <4 x i16> [[SHUFFLE]], i32 0
-; CHECK-NEXT:store i16 [[TMP1]], i16* [[A:%.*]]
+; CHECK-NEXT:store i16 [[TMP1]], i16* [[A:%.*]], align 2
 ; CHECK-NEXT:[[TMP2:%.*]] = bitcast i16* [[PTR0]] to <4 x i16>*
 ; CHECK-NEXT:store <4 x i16> [[SHUFFLE]], <4 x i16>* [[TMP2]], align 2
 ; CHECK-NEXT:ret void
@@ -41,7 +41,7 @@ define void @f2(<2 x i16> %x, i16* %a) {
 ; CHECK-NEXT:[[PTR2:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 2
 ; CHECK-NEXT:[[PTR3:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 3
 ; CHECK-NEXT:[[TMP0:%.*]] = extractelement <4 x i16> [[SHUFFLE]], i32 0
-; CHECK-NEXT:store i16 [[TMP0]], i16* [[A]]
+; CHECK-NEXT:store i16 [[TMP0]], i16* [[A]], align 2
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i16* [[PTR0]] to <4 x i16>*
 ; CHECK-NEXT:store <4 x i16> [[SHUFFLE]], <4 x i16>* [[TMP1]], align 2
 ; CHECK-NEXT:[[A_VAL:%.*]] = load i16, i16* [[A]], align 2
@@ -89,7 +89,7 @@ define void @f3(<2 x i16> %x, i16* %a) {
 ; CHECK-NEXT:[[PTR2:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 2
 ; CHECK-NEXT:[[PTR3:%.*]] = getelementptr inbounds [4 x i16], [4 x i16]* 
undef, i16 0, i16 3
 ; CHECK-NEXT:[[TMP0:%.*]] = extractelement <4 x i16> [[SHUFFLE]], i32 0
-; CHECK-NEXT:store i16 [[TMP0]], i16* [[A]]
+; CHECK-NEXT:store i16 [[TMP0]], i16* [[A]], align 2
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i16* [[PTR0]] to <4 x i16>*
 ; CHECK-NEXT:store <4 x i16> [[SHUFFLE]], <4 x i16>* [[TMP1]], align 2
 ; CHECK-NEXT:[[A_VAL:%.*]] = load i16, i16* [[A]], align 2



___
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] e7fc561 - [TEST]Autogenerate test checks, NFC.

2020-12-04 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2020-12-04T11:01:58-08:00
New Revision: e7fc561843ecf374c3b394a8ac76019f3d4bf1d6

URL: 
https://github.com/llvm/llvm-project/commit/e7fc561843ecf374c3b394a8ac76019f3d4bf1d6
DIFF: 
https://github.com/llvm/llvm-project/commit/e7fc561843ecf374c3b394a8ac76019f3d4bf1d6.diff

LOG: [TEST]Autogenerate test checks, NFC.

Added: 


Modified: 
llvm/test/Transforms/LoopVectorize/X86/pr34438.ll

Removed: 




diff  --git a/llvm/test/Transforms/LoopVectorize/X86/pr34438.ll 
b/llvm/test/Transforms/LoopVectorize/X86/pr34438.ll
index efbfecc2f54c..b30246c21950 100644
--- a/llvm/test/Transforms/LoopVectorize/X86/pr34438.ll
+++ b/llvm/test/Transforms/LoopVectorize/X86/pr34438.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; PR34438
 ; Loop has a short trip count of 8 iterations. It should be vectorized because 
no runtime checks or tail loop are necessary.
 ; Two cases tested AVX (MaxVF=8 = TripCount) and AVX512 (MaxVF=16 > TripCount)
@@ -9,9 +10,51 @@ target datalayout = 
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
 target triple = "x86_64-apple-macosx10.8.0"
 
 define void @small_tc(float* noalias nocapture %A, float* noalias nocapture 
readonly %B) {
-; CHECK-LABEL: @small_tc
-; CHECK:load <8 x float>, <8 x float>*
-; CHECK:fadd fast <8 x float>
+; CHECK-LABEL: @small_tc(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK:   vector.ph:
+; CHECK-NEXT:br label [[VECTOR_BODY:%.*]]
+; CHECK:   vector.body:
+; CHECK-NEXT:[[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ 
[[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <8 x i64> 
undef, i64 [[INDEX]], i32 0
+; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <8 x i64> 
[[BROADCAST_SPLATINSERT]], <8 x i64> undef, <8 x i32> zeroinitializer
+; CHECK-NEXT:[[INDUCTION:%.*]] = add <8 x i64> [[BROADCAST_SPLAT]], 
+; CHECK-NEXT:[[TMP0:%.*]] = add i64 [[INDEX]], 0
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds float, float* 
[[B:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr inbounds float, float* [[TMP1]], 
i32 0
+; CHECK-NEXT:[[TMP3:%.*]] = bitcast float* [[TMP2]] to <8 x float>*
+; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <8 x float>, <8 x float>* [[TMP3]], 
align 4, !llvm.access.group !0
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr inbounds float, float* 
[[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr inbounds float, float* [[TMP4]], 
i32 0
+; CHECK-NEXT:[[TMP6:%.*]] = bitcast float* [[TMP5]] to <8 x float>*
+; CHECK-NEXT:[[WIDE_LOAD1:%.*]] = load <8 x float>, <8 x float>* [[TMP6]], 
align 4, !llvm.access.group !0
+; CHECK-NEXT:[[TMP7:%.*]] = fadd fast <8 x float> [[WIDE_LOAD]], 
[[WIDE_LOAD1]]
+; CHECK-NEXT:[[TMP8:%.*]] = bitcast float* [[TMP5]] to <8 x float>*
+; CHECK-NEXT:store <8 x float> [[TMP7]], <8 x float>* [[TMP8]], align 4, 
!llvm.access.group !0
+; CHECK-NEXT:[[INDEX_NEXT]] = add i64 [[INDEX]], 8
+; CHECK-NEXT:[[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 8
+; CHECK-NEXT:br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label 
[[VECTOR_BODY]], [[LOOP1:!llvm.loop !.*]]
+; CHECK:   middle.block:
+; CHECK-NEXT:[[CMP_N:%.*]] = icmp eq i64 8, 8
+; CHECK-NEXT:br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
+; CHECK:   scalar.ph:
+; CHECK-NEXT:[[BC_RESUME_VAL:%.*]] = phi i64 [ 8, [[MIDDLE_BLOCK]] ], [ 0, 
[[ENTRY:%.*]] ]
+; CHECK-NEXT:br label [[FOR_BODY:%.*]]
+; CHECK:   for.body:
+; CHECK-NEXT:[[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], 
[[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
+; CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds float, float* 
[[B]], i64 [[INDVARS_IV]]
+; CHECK-NEXT:[[TMP10:%.*]] = load float, float* [[ARRAYIDX]], align 4, 
!llvm.access.group !0
+; CHECK-NEXT:[[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* 
[[A]], i64 [[INDVARS_IV]]
+; CHECK-NEXT:[[TMP11:%.*]] = load float, float* [[ARRAYIDX2]], align 4, 
!llvm.access.group !0
+; CHECK-NEXT:[[ADD:%.*]] = fadd fast float [[TMP10]], [[TMP11]]
+; CHECK-NEXT:store float [[ADD]], float* [[ARRAYIDX2]], align 4, 
!llvm.access.group !0
+; CHECK-NEXT:[[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
+; CHECK-NEXT:[[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 8
+; CHECK-NEXT:br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]], 
[[LOOP3:!llvm.loop !.*]]
+; CHECK:   for.end:
+; CHECK-NEXT:ret void
+;
 entry:
   br label %for.body
 



___
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] 2502f89 - [OPENMP]Fix PR48387: disable warning messages caused by internal conversions.

2020-12-04 Thread Alexey Bataev via llvm-branch-commits

Author: Alexey Bataev
Date: 2020-12-04T07:44:36-08:00
New Revision: 2502f899543151cf3d35c0fa0eef4ba681ad4e77

URL: 
https://github.com/llvm/llvm-project/commit/2502f899543151cf3d35c0fa0eef4ba681ad4e77
DIFF: 
https://github.com/llvm/llvm-project/commit/2502f899543151cf3d35c0fa0eef4ba681ad4e77.diff

LOG: [OPENMP]Fix PR48387: disable warning messages caused by internal 
conversions.

Compiler needs to convert some of the loop iteration
variables/conditions to different types for better codegen and it may
lead to spurious warning messages about implicit signed/unsigned
conversions.

Differential Revision: https://reviews.llvm.org/D92655

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/for_ast_print.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index dece57bb060aa..932017d638f5a 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4196,6 +4196,7 @@ static OMPCapturedExprDecl *buildCaptureDecl(Sema , 
IdentifierInfo *Id,
   if (!WithInit)
 CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C));
   S.CurContext->addHiddenDecl(CED);
+  Sema::TentativeAnalysisScope Trap(S);
   S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false);
   return CED;
 }
@@ -7580,6 +7581,7 @@ std::pair 
OpenMPIterationSpaceChecker::buildMinMaxValues(
   if (!Diff.isUsable())
 return std::make_pair(nullptr, nullptr);
 
+  Sema::TentativeAnalysisScope Trap(SemaRef);
   Diff = SemaRef.ActOnFinishFullExpr(Diff.get(), /*DiscardedValue=*/false);
   if (!Diff.isUsable())
 return std::make_pair(nullptr, nullptr);

diff  --git a/clang/test/OpenMP/for_ast_print.cpp 
b/clang/test/OpenMP/for_ast_print.cpp
index 15187becf2e8c..1cc68c4ad87eb 100644
--- a/clang/test/OpenMP/for_ast_print.cpp
+++ b/clang/test/OpenMP/for_ast_print.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wsign-conversion | 
FileCheck %s
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify 
%s -ast-print | FileCheck %s
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wsign-conversion | 
FileCheck %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only 
-verify %s -ast-print | FileCheck %s
 // expected-no-diagnostics
@@ -223,9 +223,9 @@ int main(int argc, char **argv) {
 // CHECK: static int a;
 #pragma omp for schedule(guided, argc) reduction(+:argv[0][:1]) 
order(concurrent)
   // CHECK-NEXT: #pragma omp for schedule(guided, argc) reduction(+: 
argv[0][:1]) order(concurrent)
-  for (int i = 0; i < 2; ++i)
+  for (int i = argc; i < c; ++i)
 a = 2;
-// CHECK-NEXT: for (int i = 0; i < 2; ++i)
+// CHECK-NEXT: for (int i = argc; i < c; ++i)
 // CHECK-NEXT: a = 2;
 #pragma omp parallel
 #pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) 
collapse(3) schedule(auto) ordered nowait linear(g:-1) reduction(task, +:e)



___
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] [cfe-branch] r288048 - Merging r287227:

2016-11-28 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Mon Nov 28 11:55:42 2016
New Revision: 288048

URL: http://llvm.org/viewvc/llvm-project?rev=288048=rev
Log:
Merging r287227:

r287227 | abataev | 2016-11-17 15:12:05 + (Thu, 17 Nov 2016) | 4 lines

[OPENMP] Fixed codegen for 'omp cancel' construct.

If 'omp cancel' construct is used in a worksharing construct it may
cause hanging of the software in case if reduction clause is used. Patch fixes 
this problem by avoiding extra reduction processing for branches that were 
canceled.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
cfe/branches/release_39/lib/CodeGen/CodeGenFunction.h
cfe/branches/release_39/test/OpenMP/cancel_codegen.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 28 11:55:42 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,280672,284110,284229,286103,286106,286129,286584,286944,286953,287025
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,280672,284110,284229,286103,286106,286129,286584,286944,286953,287025,287227
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp?rev=288048=288047=288048=diff
==
--- cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp Mon Nov 28 11:55:42 
2016
@@ -1767,17 +1767,11 @@ void CodeGenFunction::EmitOMPOuterLoop(b
   EmitBlock(LoopExit.getBlock());
 
   // Tell the runtime we are done.
-  SourceLocation ELoc = S.getLocEnd();
-  auto & = [DynamicOrOrdered, ELoc](CodeGenFunction ) {
+  auto & = [DynamicOrOrdered, ](CodeGenFunction ) {
 if (!DynamicOrOrdered)
-  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, S.getLocEnd());
   };
-  CodeGen(*this);
-
-  OpenMPDirectiveKind DKind = S.getDirectiveKind();
-  if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
-  DKind == OMPD_distribute_parallel_for)
-OMPCancelStack.back().CodeGen = CodeGen;
+  OMPCancelStack.emitExit(*this, S.getDirectiveKind(), CodeGen);
 }
 
 void CodeGenFunction::EmitOMPForOuterLoop(
@@ -1889,11 +1883,12 @@ void CodeGenFunction::EmitOMPDistributeO
 void CodeGenFunction::EmitOMPDistributeParallelForDirective(
 const OMPDistributeParallelForDirective ) {
   OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
-  OMPCancelStackRAII CancelRegion(*this);
   CGM.getOpenMPRuntime().emitInlinedDirective(
   *this, OMPD_distribute_parallel_for,
   [](CodeGenFunction , PrePostActionTy &) {
 OMPLoopScope PreInitScope(CGF, S);
+OMPCancelStackRAII CancelRegion(CGF, OMPD_distribute_parallel_for,
+/*HasCancel=*/false);
 CGF.EmitStmt(
 cast(S.getAssociatedStmt())->getCapturedStmt());
   });
@@ -2082,15 +2077,10 @@ bool CodeGenFunction::EmitOMPWorksharing
  [](CodeGenFunction &) {});
 EmitBlock(LoopExit.getBlock());
 // Tell the runtime we are done.
-SourceLocation ELoc = S.getLocEnd();
-auto & = [ELoc](CodeGenFunction ) {
-  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+auto & = [](CodeGenFunction ) {
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, S.getLocEnd());
 };
-CodeGen(*this);
-OpenMPDirectiveKind DKind = S.getDirectiveKind();
-if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
-DKind == OMPD_distribute_parallel_for)
-  OMPCancelStack.back().CodeGen = CodeGen;
+OMPCancelStack.emitExit(*this, S.getDirectiveKind(), CodeGen);
   } else {
 const bool IsMonotonic =
 Ordered || ScheduleKind.Schedule == OMPC_SCHEDULE_static ||
@@ -2140,11 +2130,11 @@ void CodeGenFunction::EmitOMPForDirectiv
   bool HasLastprivates = false;
   auto & = [, ](CodeGenFunction ,
   PrePostActionTy &) {
+OMPCancelStackRAII CancelRegion(CGF, OMPD_for, S.hasCancel());

Re: [llvm-branch-commits] [cfe-branch] r286968 - Merging r286944:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Hi,

Sorry for this mess. Fixed in r287033.

Best regards,
Alexey Bataev

On 11/15/2016 09:58 PM, Vitaly Buka wrote:
Alexey, this patch is likely the cause of 
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/197/steps/check-clang%20asan/logs/stdio

On Tue, Nov 15, 2016 at 8:59 AM Alexey Bataev via llvm-branch-commits 
<llvm-branch-commits@lists.llvm.org<mailto:llvm-branch-commits@lists.llvm.org>> 
wrote:
Author: abataev
Date: Tue Nov 15 08:26:49 2016
New Revision: 286968

URL: http://llvm.org/viewvc/llvm-project?rev=286968=rev
Log:
Merging r286944:

r286944 | abataev | 2016-11-15 09:11:50 + (Tue, 15 Nov 2016) | 6 lines

[OPENMP] Fixed codegen for 'omp cancel' construct.

If 'omp cancel' construct is used in a worksharing construct it may cause
hanging of the software in case if reduction clause is used. Patch fixes
this problem by avoiding extra reduction processing for branches that
were canceled.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
cfe/branches/release_39/lib/CodeGen/CodeGenFunction.h
cfe/branches/release_39/test/OpenMP/cancel_codegen.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 08:26:49 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584,286944
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp?rev=286968=286967=286968=diff
==
--- cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp Tue Nov 15 08:26:49 
2016
@@ -1767,9 +1767,17 @@ void CodeGenFunction::EmitOMPOuterLoop(b
   EmitBlock(LoopExit.getBlock());

   // Tell the runtime we are done.
-  if (!DynamicOrOrdered)
-RT.emitForStaticFinish(*this, S.getLocEnd());
+  SourceLocation ELoc = S.getLocEnd();
+  auto & = [DynamicOrOrdered, ELoc](CodeGenFunction ) {
+if (!DynamicOrOrdered)
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+  };
+  CodeGen(*this);

+  OpenMPDirectiveKind DKind = S.getDirectiveKind();
+  if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
+  DKind == OMPD_distribute_parallel_for)
+OMPCancelStack.back().CodeGen = CodeGen;
 }

 void CodeGenFunction::EmitOMPForOuterLoop(
@@ -1881,6 +1889,7 @@ void CodeGenFunction::EmitOMPDistributeO
 void CodeGenFunction::EmitOMPDistributeParallelForDirective(
 const OMPDistributeParallelForDirective ) {
   OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
+  OMPCancelStackRAII CancelRegion(*this);
   CGM.getOpenMPRuntime().emitInlinedDirective(
   *this, OMPD_distribute_parallel_for,
   [](CodeGenFunction , PrePostActionTy &) {
@@ -2073,7 +2082,15 @@ bool CodeGenFunction::EmitOMPWorksharing
  [](CodeGenFunction &) {});
 EmitBlock(LoopExit.getBlock());
 // Tell the runtime we are done.
-RT.emitForStaticFinish(*this, S.getLocStart());
+SourceLocation ELoc = S.getLocEnd();
+auto & = [ELoc](CodeGenFunction ) {
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+};
+CodeGen(*this);
+OpenMPDirectiveKind DKind = S.getDirectiveKind();
+if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
+DKind == OMPD_distribute_parallel_for)
+  OMPCancelStack.back().CodeGen = CodeGen;
   } else {
 const bool IsMonotonic =
 Ordered || ScheduleKind.Schedule == OMPC_SCHEDULE_static ||
@@ -2127,6 +2144,7 @@ void CodeGenFunction::EmitOMPForDirectiv
   };
   {
 OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
+OMPCancelStackRAII CancelRegion(*this);
 CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_for, CodeGen,
 S.hasCancel());
   }
@@ -2263,7 +2281,12 @@ void CodeGenFunction::EmitSections(const
 CGF.EmitOMPInnerLoop(

[llvm-branch-commits] [cfe-branch] r287033 - Merging r287025:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 15:24:19 2016
New Revision: 287033

URL: http://llvm.org/viewvc/llvm-project?rev=287033=rev
Log:
Merging r287025:

r287025 | abataev | 2016-11-15 20:57:18 + (Tue, 15 Nov 2016) | 3 lines

[OPENMP] Fix stack use after delete, NFC.

Fixed possible use of stack variable after deletion.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 15:24:19 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,284229,286103,286106,286129,286584,286944,286953
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,284229,286103,286106,286129,286584,286944,286953,287025
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp?rev=287033=287032=287033=diff
==
--- cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp Tue Nov 15 15:24:19 
2016
@@ -2187,6 +2187,7 @@ void CodeGenFunction::EmitSections(const
   bool HasLastprivates = false;
   auto & = [, Stmt, CS, ](CodeGenFunction ,
 PrePostActionTy &) {
+OMPCancelStackRAII CancelRegion(CGF);
 auto  = CGF.CGM.getContext();
 auto KmpInt32Ty = C.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1);
 // Emit helper vars inits.
@@ -2282,11 +2283,11 @@ void CodeGenFunction::EmitSections(const
  [](CodeGenFunction &) {});
 // Tell the runtime we are done.
 SourceLocation ELoc = S.getLocEnd();
-auto & = [ELoc](CodeGenFunction ) {
+auto & = [ELoc](CodeGenFunction ) {
   CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
 };
-CodeGen(CGF);
-CGF.OMPCancelStack.back().CodeGen = CodeGen;
+FinalCodeGen(CGF);
+CGF.OMPCancelStack.back().CodeGen = FinalCodeGen;
 CGF.EmitOMPReductionClauseFinal(S);
 // Emit post-update of the reduction variables if IsLastIter != 0.
 emitPostUpdateForReductionClause(
@@ -2324,7 +2325,6 @@ void CodeGenFunction::EmitSections(const
 void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective ) {
   {
 OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
-OMPCancelStackRAII CancelRegion(*this);
 EmitSections(S);
   }
   // Emit an implicit barrier at the end.
@@ -2433,7 +2433,6 @@ void CodeGenFunction::EmitOMPParallelSec
   // Emit directive as a combined directive that consists of two implicit
   // directives: 'parallel' with 'sections' directive.
   auto & = [](CodeGenFunction , PrePostActionTy &) {
-OMPCancelStackRAII CancelRegion(CGF);
 CGF.EmitSections(S);
   };
   emitCommonOMPParallelDirective(*this, S, OMPD_sections, CodeGen);


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [cfe-branch] r286970 - Merging r284229:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 08:30:48 2016
New Revision: 286970

URL: http://llvm.org/viewvc/llvm-project?rev=286970=rev
Log:
Merging r284229:

r284229 | abataev | 2016-10-14 12:43:59 + (Fri, 14 Oct 2016) | 37 lines

Fix for PR30632: Name mangling issue.

There was a bug in the implementation of captured statements. If it has
a lambda expression in it and the same lambda expression is used outside
the captured region, clang produced an error:
```
error: definition with same mangled name as another definition
```
Here is an example:
```
struct A {
 template 
 void g(const L&) { }
};

template
void f() {
  {
A().g([](){});
  }
  A().g([](){});
}

int main() {
  f();
}
```

Error report:
```
main.cpp:3:10: error: definition with same mangled name as another
definition
void g(const L&) { }
 ^
main.cpp:3:10: note: previous definition is here
```
Patch fixes this bug.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/Sema/SemaLambda.cpp
cfe/branches/release_39/test/CodeGenCXX/captured-statements.cpp
cfe/branches/release_39/test/OpenMP/for_lastprivate_codegen.cpp
cfe/branches/release_39/test/OpenMP/target_map_codegen.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 08:30:48 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584,286944
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,284229,286103,286106,286129,286584,286944,286953
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/Sema/SemaLambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaLambda.cpp?rev=286970=286969=286970=diff
==
--- cfe/branches/release_39/lib/Sema/SemaLambda.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaLambda.cpp Tue Nov 15 08:30:48 2016
@@ -314,18 +314,21 @@ Sema::getCurrentMangleNumberContext(cons
   bool IsInNonspecializedTemplate =
 !ActiveTemplateInstantiations.empty() || CurContext->isDependentContext();
   switch (Kind) {
-  case Normal:
+  case Normal: {
 //  -- the bodies of non-exported nonspecialized template functions
 //  -- the bodies of inline functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
   ManglingContextDecl = nullptr;
+  while (auto *CD = dyn_cast(DC))
+DC = CD->getParent();
   return (DC);
 }
 
 ManglingContextDecl = nullptr;
 return nullptr;
+  }
 
   case StaticDataMember:
 //  -- the initializers of nonspecialized static members of template 
classes

Modified: cfe/branches/release_39/test/CodeGenCXX/captured-statements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/CodeGenCXX/captured-statements.cpp?rev=286970=286969=286970=diff
==
--- cfe/branches/release_39/test/CodeGenCXX/captured-statements.cpp (original)
+++ cfe/branches/release_39/test/CodeGenCXX/captured-statements.cpp Tue Nov 15 
08:30:48 2016
@@ -78,6 +78,7 @@ void test3(int x) {
   {
 x = [=]() { return x + 1; } ();
   }
+  x = [=]() { return x + 1; }();
 
   // CHECK-3: %[[Capture:struct\.anon[\.0-9]*]] = type { i32* }
 

Modified: cfe/branches/release_39/test/OpenMP/for_lastprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/OpenMP/for_lastprivate_codegen.cpp?rev=286970=286969=286970=diff
==
--- cfe/branches/release_39/test/OpenMP/for_lastprivate_codegen.cpp (original)
+++ cfe/branches/release_39/test/OpenMP/for_lastprivate_codegen.cpp Tue Nov 15 
08:30:48 2016
@@ -41,7 +41,7 @@ struct SS {
 for (a = 0; a < 2; ++a)
 #ifdef LAMBDA
   [&]() {
-++this->a, --b, (this)->c /= 1;
+--this->a, ++b, (this)->c *= 2;
 #pragma omp parallel
 #pragma omp for lastprivate(b)
 for (b = 0; b < 2; ++b)
@@ -190,7 +190,7 @@ int main() {
 // LAMBDA: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, 
i{{[0-9]+}}*, 

[llvm-branch-commits] [cfe-branch] r286965 - Merging r286129:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 08:15:56 2016
New Revision: 286965

URL: http://llvm.org/viewvc/llvm-project?rev=286965=rev
Log:
Merging r286129:

r286129 | abataev | 2016-11-07 18:15:02 + (Mon, 07 Nov 2016) | 8 lines

[OPENMP] Fixed codegen for __real/__imag expressions in atomic
constructs.

For __real/__imag unary expressions clang emits lvalue with the
associated type from the original complex expression, but not the
underlying builtin integer or float type. This causes crash in codegen
for atomic constructs, if __real/__imag expression are used in atomic
  constructs.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/CodeGen/CGExpr.cpp
cfe/branches/release_39/test/OpenMP/atomic_write_codegen.c

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 08:15:56 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CGExpr.cpp?rev=286965=286964=286965=diff
==
--- cfe/branches/release_39/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CGExpr.cpp Tue Nov 15 08:15:56 2016
@@ -2248,13 +2248,15 @@ LValue CodeGenFunction::EmitUnaryOpLValu
   return LV;
 }
 
-assert(E->getSubExpr()->getType()->isAnyComplexType());
+QualType T = ExprTy->castAs()->getElementType();
 
 Address Component =
   (E->getOpcode() == UO_Real
  ? emitAddrOfRealComponent(LV.getAddress(), LV.getType())
  : emitAddrOfImagComponent(LV.getAddress(), LV.getType()));
-return MakeAddrLValue(Component, ExprTy, LV.getAlignmentSource());
+LValue ElemLV = MakeAddrLValue(Component, T, LV.getAlignmentSource());
+ElemLV.getQuals().addQualifiers(LV.getQuals());
+return ElemLV;
   }
   case UO_PreInc:
   case UO_PreDec: {

Modified: cfe/branches/release_39/test/OpenMP/atomic_write_codegen.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/OpenMP/atomic_write_codegen.c?rev=286965=286964=286965=diff
==
--- cfe/branches/release_39/test/OpenMP/atomic_write_codegen.c (original)
+++ cfe/branches/release_39/test/OpenMP/atomic_write_codegen.c Tue Nov 15 
08:15:56 2016
@@ -78,6 +78,9 @@ float2 float2x;
 register int rix __asm__("esp");
 
 int main() {
+// CHECK: store atomic i32 1, i32* getelementptr inbounds ({ i32, i32 }, { 
i32, i32 }* @civ, i32 0, i32 1) monotonic,
+#pragma omp atomic write
+ __imag(civ) = 1;
 // CHECK: load i8, i8*
 // CHECK: store atomic i8
 #pragma omp atomic write


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [cfe-branch] r286966 - Merging r286584:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 08:23:10 2016
New Revision: 286966

URL: http://llvm.org/viewvc/llvm-project?rev=286966=rev
Log:
Merging r286584:

r286584 | abataev | 2016-11-11 12:36:20 + (Fri, 11 Nov 2016) | 31 lines

Fix for PR28523: unexpected compilation error.

Clang emits error message for the following code:
```
template  void parallel_loop(F &) { f(0); }

int main() {
  int x;
  parallel_loop([&](auto y) {
{
  x = y;
};
  });
}
```

$ clang++ --std=gnu++14 clang_test.cc -o clang_test
clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing 
function 'main'
  x = y;
^
clang_test.cc:2:48: note: in instantiation of function template specialization 
'main()::(anonymous class)::operator()' requested here
template  void parallel_loop(F &) { f(0); }
   ^
clang_test.cc:6:3: note: in instantiation of function template specialization 
'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here 
parallel_loop([&](auto y) {
   ^
clang_test.cc:5:7: note: 'x' declared here
  int x;
  ^
1 error generated.

Patch fixes this issue.


Added:
cfe/branches/release_39/test/CodeGenCXX/PR28523.cpp
  - copied unchanged from r286584, cfe/trunk/test/CodeGenCXX/PR28523.cpp
Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/include/clang/Sema/Sema.h
cfe/branches/release_39/lib/Sema/Sema.cpp
cfe/branches/release_39/lib/Sema/SemaExpr.cpp
cfe/branches/release_39/lib/Sema/SemaExprCXX.cpp
cfe/branches/release_39/lib/Sema/SemaLambda.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 08:23:10 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/include/clang/Sema/Sema.h?rev=286966=286965=286966=diff
==
--- cfe/branches/release_39/include/clang/Sema/Sema.h (original)
+++ cfe/branches/release_39/include/clang/Sema/Sema.h Tue Nov 15 08:23:10 2016
@@ -1218,8 +1218,10 @@ public:
   /// \brief Retrieve the current block, if any.
   sema::BlockScopeInfo *getCurBlock();
 
-  /// \brief Retrieve the current lambda scope info, if any.
-  sema::LambdaScopeInfo *getCurLambda();
+  /// Retrieve the current lambda scope info, if any.
+  /// \param IgnoreCapturedRegions true if should find the top-most lambda 
scope
+  /// info ignoring all inner captured regions scope infos.
+  sema::LambdaScopeInfo *getCurLambda(bool IgnoreCapturedRegions = false);
 
   /// \brief Retrieve the current generic lambda info, if any.
   sema::LambdaScopeInfo *getCurGenericLambda();

Modified: cfe/branches/release_39/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/Sema.cpp?rev=286966=286965=286966=diff
==
--- cfe/branches/release_39/lib/Sema/Sema.cpp (original)
+++ cfe/branches/release_39/lib/Sema/Sema.cpp Tue Nov 15 08:23:10 2016
@@ -1197,11 +1197,19 @@ BlockScopeInfo *Sema::getCurBlock() {
   return CurBSI;
 }
 
-LambdaScopeInfo *Sema::getCurLambda() {
+LambdaScopeInfo *Sema::getCurLambda(bool IgnoreCapturedRegions) {
   if (FunctionScopes.empty())
 return nullptr;
 
-  auto CurLSI = dyn_cast(FunctionScopes.back());
+  auto I = FunctionScopes.rbegin();
+  if (IgnoreCapturedRegions) {
+auto E = FunctionScopes.rend();
+while (I != E && isa(*I))
+  ++I;
+if (I == E)
+  return nullptr;
+  }
+  auto *CurLSI = dyn_cast(*I);
   if (CurLSI && CurLSI->Lambda &&
   !CurLSI->Lambda->Encloses(CurContext)) {
 // We have switched contexts due to template instantiation.

Modified: cfe/branches/release_39/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaExpr.cpp?rev=286966=286965=286966=diff

[llvm-branch-commits] [cfe-branch] r286972 - Merging r283223:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 08:44:21 2016
New Revision: 286972

URL: http://llvm.org/viewvc/llvm-project?rev=286972=rev
Log:
Merging r283223:
r283223 | davidsh | 2016-10-04 10:41:36 -0400 (Tue, 04 Oct 2016) | 1 line

[OpenMP] fix segfault when a variable referenced in reduction clause is a 
reference parameter
Differential Revision: http://reviews.llvm.org/D24524

Modified:
cfe/branches/release_39/lib/Sema/SemaOpenMP.cpp

cfe/branches/release_39/test/OpenMP/distribute_parallel_for_reduction_messages.cpp

cfe/branches/release_39/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/distribute_simd_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/for_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/for_simd_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/parallel_for_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/parallel_for_simd_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/parallel_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/parallel_sections_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/sections_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/simd_reduction_messages.cpp

cfe/branches/release_39/test/OpenMP/target_parallel_for_reduction_messages.cpp

cfe/branches/release_39/test/OpenMP/target_parallel_for_simd_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/target_parallel_reduction_messages.cpp
cfe/branches/release_39/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/branches/release_39/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaOpenMP.cpp?rev=286972=286971=286972=diff
==
--- cfe/branches/release_39/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaOpenMP.cpp Tue Nov 15 08:44:21 2016
@@ -9133,7 +9133,7 @@ OMPClause *Sema::ActOnOpenMPReductionCla
 //  for all threads of the team.
 if (!ASE && !OASE && VD) {
   VarDecl *VDDef = VD->getDefinition();
-  if (VD->getType()->isReferenceType() && VDDef) {
+  if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) {
 DSARefChecker Check(DSAStack);
 if (Check.Visit(VDDef->getInit())) {
   Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange;

Modified: 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/OpenMP/distribute_parallel_for_reduction_messages.cpp?rev=286972=286971=286972=diff
==
--- 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
 (original)
+++ 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
 Tue Nov 15 08:44:21 2016
@@ -9,6 +9,14 @@ bool foobool(int argc) {
   return argc;
 }
 
+void foobar(int ) {
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for reduction(+:ref)
+  for (int i = 0; i < 10; ++i)
+foo();
+}
+
 struct S1; // expected-note {{declared here}} expected-note 4 {{forward 
declaration of 'S1'}}
 extern S1 a;
 class S2 {

Modified: 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp?rev=286972=286971=286972=diff
==
--- 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
 (original)
+++ 
cfe/branches/release_39/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
 Tue Nov 15 08:44:21 2016
@@ -9,6 +9,14 @@ bool foobool(int argc) {
   return argc;
 }
 
+void foobar(int ) {
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for simd reduction(+:ref)
+  for (int i = 0; i < 10; ++i)
+foo();
+}
+
 struct S1; // expected-note {{declared here}} expected-note 4 {{forward 
declaration of 'S1'}}
 extern S1 a;
 class S2 {

Modified: 
cfe/branches/release_39/test/OpenMP/distribute_simd_reduction_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/OpenMP/distribute_simd_reduction_messages.cpp?rev=286972=286971=286972=diff
==
--- cfe/branches/release_39/test/OpenMP/distribute_simd_reduction_messages.cpp 
(original)
+++ cfe/branches/release_39/test/OpenMP/distribute_simd_reduction_messages.cpp 
Tue Nov 15 08:44:21 2016
@@ -9,6 +9,14 @@ bool foobool(int argc) {
   return argc;
 }
 
+void foobar(int ) {
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute simd reduction(+:ref)
+  for (int i = 0; i < 10; ++i)
+foo();

[llvm-branch-commits] [cfe-branch] r286968 - Merging r286944:

2016-11-15 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Tue Nov 15 08:26:49 2016
New Revision: 286968

URL: http://llvm.org/viewvc/llvm-project?rev=286968=rev
Log:
Merging r286944:

r286944 | abataev | 2016-11-15 09:11:50 + (Tue, 15 Nov 2016) | 6 lines

[OPENMP] Fixed codegen for 'omp cancel' construct.

If 'omp cancel' construct is used in a worksharing construct it may cause
hanging of the software in case if reduction clause is used. Patch fixes
this problem by avoiding extra reduction processing for branches that
were canceled.


Modified:
cfe/branches/release_39/   (props changed)
cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
cfe/branches/release_39/lib/CodeGen/CodeGenFunction.h
cfe/branches/release_39/test/OpenMP/cancel_codegen.cpp

Propchange: cfe/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 15 08:26:49 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584
+/cfe/trunk:275880,275967,276102,276350,276361,276473,276653,276716,276887,276891,276900,276979,276983,277095,277138,277141,277221,277307,277522,277743,277783,277796-277797,277852,277866,277889,277900,278139,278156,278234-278235,278393,278395,278763,278786,278988,284110,286103,286106,286129,286584,286944
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp?rev=286968=286967=286968=diff
==
--- cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CGStmtOpenMP.cpp Tue Nov 15 08:26:49 
2016
@@ -1767,9 +1767,17 @@ void CodeGenFunction::EmitOMPOuterLoop(b
   EmitBlock(LoopExit.getBlock());
 
   // Tell the runtime we are done.
-  if (!DynamicOrOrdered)
-RT.emitForStaticFinish(*this, S.getLocEnd());
+  SourceLocation ELoc = S.getLocEnd();
+  auto & = [DynamicOrOrdered, ELoc](CodeGenFunction ) {
+if (!DynamicOrOrdered)
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+  };
+  CodeGen(*this);
 
+  OpenMPDirectiveKind DKind = S.getDirectiveKind();
+  if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
+  DKind == OMPD_distribute_parallel_for)
+OMPCancelStack.back().CodeGen = CodeGen;
 }
 
 void CodeGenFunction::EmitOMPForOuterLoop(
@@ -1881,6 +1889,7 @@ void CodeGenFunction::EmitOMPDistributeO
 void CodeGenFunction::EmitOMPDistributeParallelForDirective(
 const OMPDistributeParallelForDirective ) {
   OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
+  OMPCancelStackRAII CancelRegion(*this);
   CGM.getOpenMPRuntime().emitInlinedDirective(
   *this, OMPD_distribute_parallel_for,
   [](CodeGenFunction , PrePostActionTy &) {
@@ -2073,7 +2082,15 @@ bool CodeGenFunction::EmitOMPWorksharing
  [](CodeGenFunction &) {});
 EmitBlock(LoopExit.getBlock());
 // Tell the runtime we are done.
-RT.emitForStaticFinish(*this, S.getLocStart());
+SourceLocation ELoc = S.getLocEnd();
+auto & = [ELoc](CodeGenFunction ) {
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+};
+CodeGen(*this);
+OpenMPDirectiveKind DKind = S.getDirectiveKind();
+if (DKind == OMPD_for || DKind == OMPD_parallel_for ||
+DKind == OMPD_distribute_parallel_for)
+  OMPCancelStack.back().CodeGen = CodeGen;
   } else {
 const bool IsMonotonic =
 Ordered || ScheduleKind.Schedule == OMPC_SCHEDULE_static ||
@@ -2127,6 +2144,7 @@ void CodeGenFunction::EmitOMPForDirectiv
   };
   {
 OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
+OMPCancelStackRAII CancelRegion(*this);
 CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_for, CodeGen,
 S.hasCancel());
   }
@@ -2263,7 +2281,12 @@ void CodeGenFunction::EmitSections(const
 CGF.EmitOMPInnerLoop(S, /*RequiresCleanup=*/false, , , BodyGen,
  [](CodeGenFunction &) {});
 // Tell the runtime we are done.
-CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, S.getLocStart());
+SourceLocation ELoc = S.getLocEnd();
+auto & = [ELoc](CodeGenFunction ) {
+  CGF.CGM.getOpenMPRuntime().emitForStaticFinish(CGF, ELoc);
+};
+CodeGen(CGF);
+CGF.OMPCancelStack.back().CodeGen = CodeGen;
 

[llvm-branch-commits] [cfe-branch] r259160 - Merging r258307 and r258495:

2016-02-16 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Thu Jan 28 23:14:10 2016
New Revision: 259160

URL: http://llvm.org/viewvc/llvm-project?rev=259160=rev
Log:
Merging r258307 and r258495:

r258307 | abataev | 2016-01-20 15:29:47 +0300 (Wed, 20 Jan 2016) | 3 lines

[OPENMP 4.0] Fix for codegen of 'cancel' directive within 'sections' directive.
Allow to emit code for 'cancel' directive within 'sections' directive with 
single sub-section.


r258495 | abataev | 2016-01-22 11:56:50 +0300 (Fri, 22 Jan 2016) | 3 lines

[OPENMP] Generalize codegen for 'sections'-based directive.
If 'sections' directive has only one sub-section, the code for 'single'-based 
directive was emitted. Removed this codegen, because it causes crashes in 
different cases.



Modified:
cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp
cfe/branches/release_38/test/OpenMP/cancel_codegen.cpp
cfe/branches/release_38/test/OpenMP/cancellation_point_codegen.cpp
cfe/branches/release_38/test/OpenMP/parallel_sections_codegen.cpp
cfe/branches/release_38/test/OpenMP/sections_codegen.cpp
cfe/branches/release_38/test/OpenMP/sections_firstprivate_codegen.cpp
cfe/branches/release_38/test/OpenMP/sections_lastprivate_codegen.cpp
cfe/branches/release_38/test/OpenMP/sections_private_codegen.cpp
cfe/branches/release_38/test/OpenMP/sections_reduction_codegen.cpp

Modified: cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp?rev=259160=259159=259160=diff
==
--- cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan 28 23:14:10 
2016
@@ -483,7 +483,7 @@ llvm::Value *CGOpenMPRuntime::getThreadI
 if (ThreadID != nullptr)
   return ThreadID;
   }
-  if (auto OMPRegionInfo =
+  if (auto *OMPRegionInfo =
   dyn_cast_or_null(CGF.CapturedStmtInfo)) {
 if (OMPRegionInfo->getThreadIDVariable()) {
   // Check if this an outlined function with thread id passed as argument.
@@ -1356,7 +1356,7 @@ void CGOpenMPRuntime::emitParallelCall(C
 // return the address of that temp.
 Address CGOpenMPRuntime::emitThreadIDAddress(CodeGenFunction ,
  SourceLocation Loc) {
-  if (auto OMPRegionInfo =
+  if (auto *OMPRegionInfo =
   dyn_cast_or_null(CGF.CapturedStmtInfo))
 if (OMPRegionInfo->getThreadIDVariable())
   return OMPRegionInfo->getThreadIDVariableLValue(CGF).getAddress();
@@ -1717,15 +1717,10 @@ void CGOpenMPRuntime::emitBarrierCall(Co
   }
   // Build call __kmpc_cancel_barrier(loc, thread_id) or __kmpc_barrier(loc,
   // thread_id);
-  auto *OMPRegionInfo =
-  dyn_cast_or_null(CGF.CapturedStmtInfo);
-  // Do not emit barrier call in the single directive emitted in some rare 
cases
-  // for sections directives.
-  if (OMPRegionInfo && OMPRegionInfo->getDirectiveKind() == OMPD_single)
-return;
   llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc, Flags),
  getThreadID(CGF, Loc)};
-  if (OMPRegionInfo) {
+  if (auto *OMPRegionInfo =
+  dyn_cast_or_null(CGF.CapturedStmtInfo)) {
 if (!ForceSimpleCall && OMPRegionInfo->hasCancel()) {
   auto *Result = CGF.EmitRuntimeCall(
   createRuntimeFunction(OMPRTL__kmpc_cancel_barrier), Args);
@@ -3649,8 +3644,6 @@ void CGOpenMPRuntime::emitCancellationPo
   // global_tid, kmp_int32 cncl_kind);
   if (auto *OMPRegionInfo =
   dyn_cast_or_null(CGF.CapturedStmtInfo)) {
-if (OMPRegionInfo->getDirectiveKind() == OMPD_single)
-  return;
 if (OMPRegionInfo->hasCancel()) {
   llvm::Value *Args[] = {
   emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
@@ -3687,8 +3680,6 @@ void CGOpenMPRuntime::emitCancelCall(Cod
   // kmp_int32 cncl_kind);
   if (auto *OMPRegionInfo =
   dyn_cast_or_null(CGF.CapturedStmtInfo)) {
-if (OMPRegionInfo->getDirectiveKind() == OMPD_single)
-  return;
 auto & = [this, Loc, CancelRegion,
   OMPRegionInfo](CodeGenFunction ) {
   llvm::Value *Args[] = {

Modified: cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp?rev=259160=259159=259160=diff
==
--- cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp Thu Jan 28 23:14:10 
2016
@@ -1657,50 +1657,51 @@ OpenMPDirectiveKind
 CodeGenFunction::EmitSections(const OMPExecutableDirective ) {
   

[llvm-branch-commits] [cfe-branch] r258483 - Merging r258394:

2016-01-22 Thread Alexey Bataev via llvm-branch-commits
Author: abataev
Date: Thu Jan 21 22:07:48 2016
New Revision: 258483

URL: http://llvm.org/viewvc/llvm-project?rev=258483=rev
Log:
Merging r258394:

r258394 | abataev | 2016-01-21 15:35:58 +0300 (Thu, 21 Jan 2016) | 3 lines

[OPENMP] Fix crash on reduction for complex variables.
reworked codegen for reduction operation for complex types to avoid crash



Modified:
cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp
cfe/branches/release_38/lib/CodeGen/CodeGenFunction.h
cfe/branches/release_38/test/OpenMP/parallel_reduction_codegen.cpp

Modified: cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp?rev=258483=258482=258483=diff
==
--- cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/branches/release_38/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan 21 22:07:48 
2016
@@ -3548,14 +3548,16 @@ void CGOpenMPRuntime::emitReduction(Code
   E = CGF.EmitAnyExpr(EExpr);
 CGF.EmitOMPAtomicSimpleUpdateExpr(
 X, E, BO, /*IsXLHSInRHSPart=*/true, llvm::Monotonic, Loc,
-[, UpExpr, VD, IPriv](RValue XRValue) {
+[, UpExpr, VD, IPriv, Loc](RValue XRValue) {
   CodeGenFunction::OMPPrivateScope PrivateScope(CGF);
-  PrivateScope.addPrivate(VD, [, VD, XRValue]() -> Address 
{
-Address LHSTemp = CGF.CreateMemTemp(VD->getType());
-CGF.EmitStoreThroughLValue(
-XRValue, CGF.MakeAddrLValue(LHSTemp, VD->getType()));
-return LHSTemp;
-  });
+  PrivateScope.addPrivate(
+  VD, [, VD, XRValue, Loc]() -> Address {
+Address LHSTemp = CGF.CreateMemTemp(VD->getType());
+CGF.emitOMPSimpleStore(
+CGF.MakeAddrLValue(LHSTemp, VD->getType()), 
XRValue,
+VD->getType().getNonReferenceType(), Loc);
+return LHSTemp;
+  });
   (void)PrivateScope.Privatize();
   return CGF.EmitAnyExpr(UpExpr);
 });

Modified: cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp?rev=258483=258482=258483=diff
==
--- cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_38/lib/CodeGen/CGStmtOpenMP.cpp Thu Jan 21 22:07:48 
2016
@@ -2163,17 +2163,17 @@ static void emitSimpleAtomicStore(CodeGe
   }
 }
 
-static void emitSimpleStore(CodeGenFunction , LValue LVal, RValue RVal,
-QualType RValTy, SourceLocation Loc) {
-  switch (CGF.getEvaluationKind(LVal.getType())) {
+void CodeGenFunction::emitOMPSimpleStore(LValue LVal, RValue RVal,
+ QualType RValTy, SourceLocation Loc) {
+  switch (getEvaluationKind(LVal.getType())) {
   case TEK_Scalar:
-CGF.EmitStoreThroughLValue(RValue::get(convertToScalarValue(
-   CGF, RVal, RValTy, LVal.getType(), Loc)),
-   LVal);
+EmitStoreThroughLValue(RValue::get(convertToScalarValue(
+   *this, RVal, RValTy, LVal.getType(), Loc)),
+   LVal);
 break;
   case TEK_Complex:
-CGF.EmitStoreOfComplex(
-convertToComplexValue(CGF, RVal, RValTy, LVal.getType(), Loc), LVal,
+EmitStoreOfComplex(
+convertToComplexValue(*this, RVal, RValTy, LVal.getType(), Loc), LVal,
 /*isInit=*/false);
 break;
   case TEK_Aggregate:
@@ -2201,7 +2201,7 @@ static void EmitOMPAtomicReadExpr(CodeGe
   // list.
   if (IsSeqCst)
 CGF.CGM.getOpenMPRuntime().emitFlush(CGF, llvm::None, Loc);
-  emitSimpleStore(CGF, VLValue, Res, X->getType().getNonReferenceType(), Loc);
+  CGF.emitOMPSimpleStore(VLValue, Res, X->getType().getNonReferenceType(), 
Loc);
 }
 
 static void EmitOMPAtomicWriteExpr(CodeGenFunction , bool IsSeqCst,
@@ -2459,7 +2459,7 @@ static void EmitOMPAtomicCaptureExpr(Cod
 }
   }
   // Emit post-update store to 'v' of old/new 'x' value.
-  emitSimpleStore(CGF, VLValue, NewVVal, NewVValType, Loc);
+  CGF.emitOMPSimpleStore(VLValue, NewVVal, NewVValType, Loc);
   // OpenMP, 2.12.6, atomic Construct
   // Any atomic construct with a seq_cst clause forces the atomically
   // performed operation to include an implicit flush operation without a

Modified: cfe/branches/release_38/lib/CodeGen/CodeGenFunction.h