Skip to content

Commit 89e8e63

Browse files
committed
[Attributor] Stabilize llvm.assume output
Don't rely on the iteration order of DenseSet<StringRef>, which is not guaranteed to be deterministic.
1 parent cae6d45 commit 89e8e63

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11739,11 +11739,14 @@ struct AAAssumptionInfoImpl : public AAAssumptionInfo {
1173911739
return ChangeStatus::UNCHANGED;
1174011740

1174111741
const IRPosition &IRP = getIRPosition();
11742-
return A.manifestAttrs(
11743-
IRP,
11744-
Attribute::get(IRP.getAnchorValue().getContext(), AssumptionAttrKey,
11745-
llvm::join(getAssumed().getSet(), ",")),
11746-
/* ForceReplace */ true);
11742+
SmallVector<StringRef, 0> Set(getAssumed().getSet().begin(),
11743+
getAssumed().getSet().end());
11744+
llvm::sort(Set);
11745+
return A.manifestAttrs(IRP,
11746+
Attribute::get(IRP.getAnchorValue().getContext(),
11747+
AssumptionAttrKey,
11748+
llvm::join(Set, ",")),
11749+
/*ForceReplace=*/true);
1174711750
}
1174811751

1174911752
bool hasAssumption(const StringRef Assumption) const override {
@@ -11755,13 +11758,15 @@ struct AAAssumptionInfoImpl : public AAAssumptionInfo {
1175511758
const SetContents &Known = getKnown();
1175611759
const SetContents &Assumed = getAssumed();
1175711760

11758-
const std::string KnownStr =
11759-
llvm::join(Known.getSet().begin(), Known.getSet().end(), ",");
11760-
const std::string AssumedStr =
11761-
(Assumed.isUniversal())
11762-
? "Universal"
11763-
: llvm::join(Assumed.getSet().begin(), Assumed.getSet().end(), ",");
11761+
SmallVector<StringRef, 0> Set(Known.getSet().begin(), Known.getSet().end());
11762+
llvm::sort(Set);
11763+
const std::string KnownStr = llvm::join(Set, ",");
1176411764

11765+
std::string AssumedStr = "Universal";
11766+
if (!Assumed.isUniversal()) {
11767+
Set.assign(Assumed.getSet().begin(), Assumed.getSet().end());
11768+
AssumedStr = llvm::join(Set, ",");
11769+
}
1176511770
return "Known [" + KnownStr + "]," + " Assumed [" + AssumedStr + "]";
1176611771
}
1176711772
};

llvm/test/Transforms/Attributor/assumes_info.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ attributes #2 = { "llvm.assume"="B,C" }
117117
attributes #3 = { "llvm.assume"="B,C,A" }
118118
;.
119119
; TUNIT: attributes #[[ATTR0]] = { "llvm.assume"="A" }
120-
; TUNIT: attributes #[[ATTR1]] = { "llvm.assume"="B,A" }
121-
; TUNIT: attributes #[[ATTR2]] = { "llvm.assume"="B,C,A" }
120+
; TUNIT: attributes #[[ATTR1]] = { "llvm.assume"="A,B" }
121+
; TUNIT: attributes #[[ATTR2]] = { "llvm.assume"="A,B,C" }
122122
;.
123123
; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="A" }
124-
; CGSCC: attributes #[[ATTR1]] = { "llvm.assume"="B,A" }
125-
; CGSCC: attributes #[[ATTR2]] = { "llvm.assume"="B,C,A" }
124+
; CGSCC: attributes #[[ATTR1]] = { "llvm.assume"="A,B" }
125+
; CGSCC: attributes #[[ATTR2]] = { "llvm.assume"="A,B,C" }
126126
; CGSCC: attributes #[[ATTR3]] = { "llvm.assume"="B" }
127127
;.

llvm/test/Transforms/OpenMP/spmdization_guarding.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ attributes #5 = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_ame
431431
; CHECK: attributes #[[ATTR6]] = { nounwind }
432432
; CHECK: attributes #[[ATTR7:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
433433
; CHECK: attributes #[[ATTR8:[0-9]+]] = { convergent nounwind }
434-
; CHECK: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
435-
; CHECK: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
434+
; CHECK: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
435+
; CHECK: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
436436
;.
437437
; CHECK-DISABLED: attributes #[[ATTR0]] = { convergent norecurse nounwind "frame-pointer"="all" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
438438
; CHECK-DISABLED: attributes #[[ATTR1:[0-9]+]] = { alwaysinline }
@@ -443,8 +443,8 @@ attributes #5 = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_ame
443443
; CHECK-DISABLED: attributes #[[ATTR6]] = { nounwind }
444444
; CHECK-DISABLED: attributes #[[ATTR7:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
445445
; CHECK-DISABLED: attributes #[[ATTR8:[0-9]+]] = { convergent nounwind }
446-
; CHECK-DISABLED: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
447-
; CHECK-DISABLED: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
446+
; CHECK-DISABLED: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
447+
; CHECK-DISABLED: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
448448
;.
449449
; CHECK: [[META0:![0-9]+]] = !{i32 0, i32 42, i32 16513658, !"sequential_loop", i32 6, i32 0}
450450
; CHECK: [[META1:![0-9]+]] = !{ptr @__omp_offloading_2a_fbfa7a_sequential_loop_l6, !"kernel", i32 1}

0 commit comments

Comments
 (0)