Skip to content

Commit 6705f63

Browse files
committed
Attributor: Start looking at uses when inferring nofpclass
Pretty much just copy pasted from noundef handling
1 parent a171e98 commit 6705f63

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10234,6 +10234,33 @@ struct AANoFPClassImpl : AANoFPClass {
1023410234
}
1023510235
}
1023610236

10237+
/// See followUsesInMBEC
10238+
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I,
10239+
AANoFPClass::StateType &State) {
10240+
const Value *UseV = U->get();
10241+
const DominatorTree *DT = nullptr;
10242+
AssumptionCache *AC = nullptr;
10243+
const TargetLibraryInfo *TLI = nullptr;
10244+
InformationCache &InfoCache = A.getInfoCache();
10245+
10246+
if (Function *F = getAnchorScope()) {
10247+
DT = InfoCache.getAnalysisResultForFunction<DominatorTreeAnalysis>(*F);
10248+
AC = InfoCache.getAnalysisResultForFunction<AssumptionAnalysis>(*F);
10249+
TLI = InfoCache.getTargetLibraryInfoForFunction(*F);
10250+
}
10251+
10252+
const DataLayout &DL = A.getDataLayout();
10253+
10254+
KnownFPClass KnownFPClass =
10255+
computeKnownFPClass(UseV, DL,
10256+
/*InterestedClasses=*/fcAllFlags,
10257+
/*Depth=*/0, TLI, AC, I, DT);
10258+
State.addKnownBits(~KnownFPClass.KnownFPClasses);
10259+
10260+
bool TrackUse = false;
10261+
return TrackUse;
10262+
}
10263+
1023710264
const std::string getAsStr() const override {
1023810265
std::string Result = "nofpclass";
1023910266
raw_string_ostream OS(Result);
@@ -10251,9 +10278,39 @@ struct AANoFPClassFloating : public AANoFPClassImpl {
1025110278
AANoFPClassFloating(const IRPosition &IRP, Attributor &A)
1025210279
: AANoFPClassImpl(IRP, A) {}
1025310280

10281+
/// See AbstractAttribute::initialize(...).
10282+
void initialize(Attributor &A) override {
10283+
AANoFPClassImpl::initialize(A);
10284+
}
10285+
1025410286
/// See AbstractAttribute::updateImpl(...).
1025510287
ChangeStatus updateImpl(Attributor &A) override {
10256-
return indicatePessimisticFixpoint();
10288+
SmallVector<AA::ValueAndContext> Values;
10289+
bool UsedAssumedInformation = false;
10290+
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values,
10291+
AA::AnyScope, UsedAssumedInformation)) {
10292+
Values.push_back({getAssociatedValue(), getCtxI()});
10293+
}
10294+
10295+
StateType T;
10296+
auto VisitValueCB = [&](Value &V, const Instruction *CtxI) -> bool {
10297+
const auto &AA = A.getAAFor<AANoFPClass>(*this, IRPosition::value(V),
10298+
DepClassTy::REQUIRED);
10299+
if (this == &AA) {
10300+
T.indicatePessimisticFixpoint();
10301+
} else {
10302+
const AANoFPClass::StateType &S =
10303+
static_cast<const AANoFPClass::StateType &>(AA.getState());
10304+
T ^= S;
10305+
}
10306+
return T.isValidState();
10307+
};
10308+
10309+
for (const auto &VAC : Values)
10310+
if (!VisitValueCB(*VAC.getValue(), VAC.getCtxI()))
10311+
return indicatePessimisticFixpoint();
10312+
10313+
return clampStateAndIndicateChange(getState(), T);
1025710314
}
1025810315

1025910316
/// See AbstractAttribute::trackStatistics()

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ define void @arg_used_by_nofpclass_nan_callsite(float %arg) {
167167
define void @ninf_arg_used_by_nofpclass_nan_callsite(float nofpclass(inf) %arg) {
168168
; CHECK-LABEL: define void @ninf_arg_used_by_nofpclass_nan_callsite
169169
; CHECK-SAME: (float nofpclass(inf) [[ARG:%.*]]) {
170-
; CHECK-NEXT: call void @extern.use(float nofpclass(nan) [[ARG]])
170+
; CHECK-NEXT: call void @extern.use(float nofpclass(nan inf) [[ARG]])
171171
; CHECK-NEXT: ret void
172172
;
173173
call void @extern.use(float nofpclass(nan) %arg)
@@ -260,7 +260,7 @@ define float @fcmp_uno_check(float %arg) local_unnamed_addr {
260260
; CHECK-NEXT: [[ISNAN:%.*]] = fcmp uno float [[ARG]], 0.000000e+00
261261
; CHECK-NEXT: br i1 [[ISNAN]], label [[BB0:%.*]], label [[BB1:%.*]]
262262
; CHECK: bb0:
263-
; CHECK-NEXT: [[CALL:%.*]] = call float @ret_nofpclass_nan()
263+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan) float @ret_nofpclass_nan()
264264
; CHECK-NEXT: br label [[BB1]]
265265
; CHECK: bb1:
266266
; CHECK-NEXT: [[PHI:%.*]] = phi float [ [[CALL]], [[BB0]] ], [ [[ARG]], [[ENTRY:%.*]] ]

0 commit comments

Comments
 (0)