Skip to content

Commit

Permalink
[Attributor] Stabilize llvm.assume output
Browse files Browse the repository at this point in the history
Don't rely on the iteration order of DenseSet<StringRef>, which is not
guaranteed to be deterministic.
  • Loading branch information
MaskRay committed Jun 19, 2024
1 parent cae6d45 commit 89e8e63
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
27 changes: 16 additions & 11 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11739,11 +11739,14 @@ struct AAAssumptionInfoImpl : public AAAssumptionInfo {
return ChangeStatus::UNCHANGED;

const IRPosition &IRP = getIRPosition();
return A.manifestAttrs(
IRP,
Attribute::get(IRP.getAnchorValue().getContext(), AssumptionAttrKey,
llvm::join(getAssumed().getSet(), ",")),
/* ForceReplace */ true);
SmallVector<StringRef, 0> Set(getAssumed().getSet().begin(),
getAssumed().getSet().end());
llvm::sort(Set);
return A.manifestAttrs(IRP,
Attribute::get(IRP.getAnchorValue().getContext(),
AssumptionAttrKey,
llvm::join(Set, ",")),
/*ForceReplace=*/true);
}

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

const std::string KnownStr =
llvm::join(Known.getSet().begin(), Known.getSet().end(), ",");
const std::string AssumedStr =
(Assumed.isUniversal())
? "Universal"
: llvm::join(Assumed.getSet().begin(), Assumed.getSet().end(), ",");
SmallVector<StringRef, 0> Set(Known.getSet().begin(), Known.getSet().end());
llvm::sort(Set);
const std::string KnownStr = llvm::join(Set, ",");

std::string AssumedStr = "Universal";
if (!Assumed.isUniversal()) {
Set.assign(Assumed.getSet().begin(), Assumed.getSet().end());
AssumedStr = llvm::join(Set, ",");
}
return "Known [" + KnownStr + "]," + " Assumed [" + AssumedStr + "]";
}
};
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Transforms/Attributor/assumes_info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ attributes #2 = { "llvm.assume"="B,C" }
attributes #3 = { "llvm.assume"="B,C,A" }
;.
; TUNIT: attributes #[[ATTR0]] = { "llvm.assume"="A" }
; TUNIT: attributes #[[ATTR1]] = { "llvm.assume"="B,A" }
; TUNIT: attributes #[[ATTR2]] = { "llvm.assume"="B,C,A" }
; TUNIT: attributes #[[ATTR1]] = { "llvm.assume"="A,B" }
; TUNIT: attributes #[[ATTR2]] = { "llvm.assume"="A,B,C" }
;.
; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="A" }
; CGSCC: attributes #[[ATTR1]] = { "llvm.assume"="B,A" }
; CGSCC: attributes #[[ATTR2]] = { "llvm.assume"="B,C,A" }
; CGSCC: attributes #[[ATTR1]] = { "llvm.assume"="A,B" }
; CGSCC: attributes #[[ATTR2]] = { "llvm.assume"="A,B,C" }
; CGSCC: attributes #[[ATTR3]] = { "llvm.assume"="B" }
;.
8 changes: 4 additions & 4 deletions llvm/test/Transforms/OpenMP/spmdization_guarding.ll
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ attributes #5 = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_ame
; CHECK: attributes #[[ATTR6]] = { nounwind }
; CHECK: attributes #[[ATTR7:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
; CHECK: attributes #[[ATTR8:[0-9]+]] = { convergent nounwind }
; CHECK: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
; CHECK: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
; CHECK: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
; CHECK: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
;.
; 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" }
; CHECK-DISABLED: attributes #[[ATTR1:[0-9]+]] = { alwaysinline }
Expand All @@ -443,8 +443,8 @@ attributes #5 = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_ame
; CHECK-DISABLED: attributes #[[ATTR6]] = { nounwind }
; CHECK-DISABLED: attributes #[[ATTR7:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
; CHECK-DISABLED: attributes #[[ATTR8:[0-9]+]] = { convergent nounwind }
; CHECK-DISABLED: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
; CHECK-DISABLED: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="ompx_spmd_amenable,omp_no_openmp" }
; CHECK-DISABLED: attributes #[[ATTR9]] = { nounwind willreturn "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
; CHECK-DISABLED: attributes #[[ATTR10]] = { convergent nounwind "llvm.assume"="omp_no_openmp,ompx_spmd_amenable" }
;.
; CHECK: [[META0:![0-9]+]] = !{i32 0, i32 42, i32 16513658, !"sequential_loop", i32 6, i32 0}
; CHECK: [[META1:![0-9]+]] = !{ptr @__omp_offloading_2a_fbfa7a_sequential_loop_l6, !"kernel", i32 1}
Expand Down

0 comments on commit 89e8e63

Please sign in to comment.