[PATCH] D75101: [OpenMP] Fix insertion point for deduplicated runtime call to honor def-use order
Wenlei He via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 23:38:52 PST 2020
wenlei created this revision.
wenlei added reviewers: jdoerfert, JonChesterfield, hoyFB.
Herald added subscribers: llvm-commits, guansong, hiraditya.
Herald added a project: LLVM.
A recently added OpenMP optimization pass (D69930 <https://reviews.llvm.org/D69930>) tries to deduplicate omp runtime calls by merging the calls and insert a new one in entry block. However the insertion didn't honor def-use chain of parameters, so it can introduce use-before-def. This change fixed the problem by taking def-use into account for finding insertion point of the merged runtime call.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75101
Files:
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/gtid.ll
Index: llvm/test/Transforms/OpenMP/gtid.ll
===================================================================
--- llvm/test/Transforms/OpenMP/gtid.ll
+++ llvm/test/Transforms/OpenMP/gtid.ll
@@ -15,7 +15,8 @@
; CHECK-LABEL: define {{[^@]+}}@external
; CHECK-SAME: (i1 [[C:%.*]])
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[C2:%.*]] = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull @0)
+; CHECK-NEXT: %tmp1 = alloca %struct.ident_t
+; CHECK-NEXT: [[C2:%.*]] = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull %tmp1)
; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[E:%.*]]
; CHECK: t:
; CHECK-NEXT: call void @internal(i32 [[C2]], i32 [[C2]])
@@ -31,19 +32,20 @@
; CHECK-NEXT: ret void
;
entry:
+ %tmp1 = alloca %struct.ident_t, align 8
br i1 %c, label %t, label %e
t:
- %c0 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull @0)
+ %c0 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull %tmp1)
call void @internal(i32 %c0, i32 %c0)
call void @useI32(i32 %c0)
br label %m
e:
- %c1 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull @0)
+ %c1 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull %tmp1)
call void @internal(i32 %c1, i32 %c1)
call void @useI32(i32 %c1)
br label %m
m:
- %c2 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull @0)
+ %c2 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull %tmp1)
call void @internal(i32 0, i32 %c2)
call void @useI32(i32 %c2)
ret void
Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -219,7 +219,16 @@
if (!ReplVal) {
for (Use *U : Uses)
if (CallInst *CI = getCallIfRegularCall(*U, &RFI)) {
- CI->moveBefore(&*F.getEntryBlock().getFirstInsertionPt());
+ Value *Op0 = CI->getOperand(0);
+ Instruction *MovePt = &*F.getEntryBlock().getFirstInsertionPt();
+ if (Instruction *DefInst = dyn_cast<Instruction>(Op0)) {
+ if (DefInst->getParent() != &F.getEntryBlock())
+ break;
+ if (!DefInst->comesBefore(MovePt)) {
+ MovePt = DefInst->getNextNode();
+ }
+ }
+ CI->moveBefore(MovePt);
ReplVal = CI;
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75101.246370.patch
Type: text/x-patch
Size: 2459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200225/83d5eb98/attachment.bin>
More information about the llvm-commits
mailing list