Skip to content

Commit dc3b5b0

Browse files
committed
[OpenMPOpt] Make the combination of ident_t* deterministic
Before we kept the first applicable `ident_t*` during deduplication of runtime calls. The problem is that "first" is dependent on the iteration order of a DenseMap. Since the proper solution, which is to combine the information from all `ident_t*`, should be deterministic on its own, we will not try to make the iteration order deterministic. Instead, we will create a fresh `ident_t*` if there is not a unique existing `ident_t*` to pick.
1 parent 8855fec commit dc3b5b0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,17 @@ struct OpenMPOpt {
235235
return Changed;
236236
}
237237

238-
static Value *combinedIdentStruct(Value *Ident0, Value *Ident1,
239-
bool GlobalOnly) {
238+
static Value *combinedIdentStruct(Value *CurrentIdent, Value *NextIdent,
239+
bool GlobalOnly, bool &SingleChoice) {
240+
if (CurrentIdent == NextIdent)
241+
return CurrentIdent;
242+
240243
// TODO: Figure out how to actually combine multiple debug locations. For
241-
// now we just keep the first we find.
242-
if (Ident0)
243-
return Ident0;
244-
if (!GlobalOnly || isa<GlobalValue>(Ident1))
245-
return Ident1;
244+
// now we just keep an existing one if there is a single choice.
245+
if (!GlobalOnly || isa<GlobalValue>(NextIdent)) {
246+
SingleChoice = !CurrentIdent;
247+
return NextIdent;
248+
}
246249
return nullptr;
247250
}
248251

@@ -253,18 +256,19 @@ struct OpenMPOpt {
253256
/// information, e.g., the source locations, see combinedIdentStruct.
254257
Value *getCombinedIdentFromCallUsesIn(RuntimeFunctionInfo &RFI, Function &F,
255258
bool GlobalOnly) {
259+
bool SingleChoice = true;
256260
Value *Ident = nullptr;
257261
auto CombineIdentStruct = [&](Use &U, Function &Caller) {
258262
CallInst *CI = getCallIfRegularCall(U, &RFI);
259263
if (!CI || &F != &Caller)
260264
return false;
261265
Ident = combinedIdentStruct(Ident, CI->getArgOperand(0),
262-
/* GlobalOnly */ true);
266+
/* GlobalOnly */ true, SingleChoice);
263267
return false;
264268
};
265269
RFI.foreachUse(CombineIdentStruct);
266270

267-
if (!Ident) {
271+
if (!Ident || !SingleChoice) {
268272
// The IRBuilder uses the insertion block to get to the module, this is
269273
// unfortunate but we work around it for now.
270274
if (!OMPBuilder.getInsertionPoint().getBlock())

llvm/test/Transforms/OpenMP/deduplication.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ m:
104104
define void @local_and_global_gtid_calls() {
105105
; CHECK-LABEL: define {{[^@]+}}@local_and_global_gtid_calls()
106106
; CHECK-NEXT: entry:
107-
; CHECK-NEXT: [[TID5:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
107+
; CHECK-NEXT: [[TID5:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @3)
108108
; CHECK-NEXT: [[DOTKMPC_LOC_ADDR:%.*]] = alloca [[STRUCT_IDENT_T:%.*]], align 8
109109
; CHECK-NEXT: call void @useI32(i32 [[TID5]])
110110
; CHECK-NEXT: call void @useI32(i32 [[TID5]])

0 commit comments

Comments
 (0)