[PATCH] D75893: [OpenMP] Add !range metadata to loads from omp.(ub/lb)

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 19 22:27:08 PDT 2020


jdoerfert added a comment.

The entire potentially reachable thing breaks down if you put the `omp for` into another loop, doesn't it? Everything becomes potentially reachable from everything.
The situation you are after is, as far as I understand, as follows:

  store x in UB
  call __kmpc_for_init_4(...)
  v = load UB
  store min(v, x) in UB

correct?

Two alternative approaches:

1. move the min computation (if necessary) into `__kmpc_for_init_4` so we don't see it here. All we would see is a single store. (=make sure the call never returns a value higher than the given upper bound) [preferred if plausible]
2. match the pattern manually. Two stores, one with a value the other with a select that implements a min. The load flowing into the min needs to (directly) follow the call, the compare etc. So the instruction sequence after the call needs to be

  call void @__kmpc_for_static_init_4(%struct.ident_t* nonnull @0, i32 %0, i32 34, i32* nonnull %.omp.is_last, i32* nonnull %.omp.lb, i32* nonnull %.omp.ub, i32* nonnull %.omp.stride, i32 1, i32 1)
  %1 = load i32, i32* %.omp.ub, align 4
  %2 = icmp slt i32 %1, 195
  %cond = select i1 %2, i32 %1, i32 195
  store i32 %cond, i32* %.omp.ub, align 4

My earlier suggestion with te must-be-executed-context was a generalization of 2). You can also do it more general without the context:

- Both stores are in the same block, on before one after the call, the second one stores the min expression, only the load that flows into the min is between the call and the second store.



================
Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:292
+            }
+          };
+
----------------
I guess this can just be a member function.


================
Comment at: llvm/test/Transforms/OpenMP/set_bound_ranges.ll:2
+; RUN: opt -openmpopt -S < %s | FileCheck %s
+; RUN: opt -passes=openmpopt -S < %s | FileCheck %s
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
----------------
manually run -simplifycfg on this file to get rid of the control flow in favor of selects and then -instcombine to remove redundant loads.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75893/new/

https://reviews.llvm.org/D75893





More information about the llvm-commits mailing list