Skip to content

Commit ecf5915

Browse files
committed
fix
Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent d4a7468 commit ecf5915

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

llvm/lib/SYCLLowerIR/SYCLSqrtFDivMaxErrorCleanUp.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static constexpr char FDIV_ERROR[] = "2.5";
3131
PreservedAnalyses
3232
SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
3333
ModuleAnalysisManager &MAM) {
34+
SmallVector<std::pair<Instruction*, Instruction*>, 16> Replaces;
3435
SmallVector<IntrinsicInst *, 16> WorkListSqrt;
3536
SmallVector<IntrinsicInst *, 16> WorkListFDiv;
3637

@@ -122,10 +123,11 @@ SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
122123
Attrs = Attrs.removeFnAttribute(Sqrt->getContext(), "fpbuiltin-max-error");
123124
NewSqrt->setAttributes(Attrs);
124125
NewSqrt->copyMetadata(*Sqrt);
125-
FPMathOperator *FPOp = cast<FPMathOperator>(Sqrt);
126-
FastMathFlags FMF = FPOp->getFastMathFlags();
127-
NewSqrt->setFastMathFlags(FMF);
128-
Sqrt->replaceAllUsesWith(NewSqrt);
126+
if (FPMathOperator *FPOp = dyn_cast<FPMathOperator>(Sqrt)) {
127+
FastMathFlags FMF = FPOp->getFastMathFlags();
128+
NewSqrt->setFastMathFlags(FMF);
129+
}
130+
Replaces.emplace_back(std::make_pair(Sqrt, NewSqrt));
129131
InstsToRemove.push_back(Sqrt);
130132
}
131133

@@ -140,13 +142,17 @@ SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
140142

141143
// Copy FP flags and metadata. Replace old call with a new instruction.
142144
cast<Instruction>(NewFDiv)->copyMetadata(*FDiv);
143-
FPMathOperator *FPOp = cast<FPMathOperator>(FDiv);
144-
FastMathFlags FMF = FPOp->getFastMathFlags();
145-
NewFDiv->setFastMathFlags(FMF);
146-
FDiv->replaceAllUsesWith(NewFDiv);
145+
if (FPMathOperator *FPOp = dyn_cast<FPMathOperator>(FDiv)) {
146+
FastMathFlags FMF = FPOp->getFastMathFlags();
147+
NewFDiv->setFastMathFlags(FMF);
148+
}
149+
Replaces.emplace_back(std::make_pair(FDiv, NewFDiv));
147150
InstsToRemove.push_back(FDiv);
148151
}
149152

153+
for (const auto &InstPair : Replaces)
154+
InstPair.first->replaceAllUsesWith(InstPair.second);
155+
150156
// Clear instructions.
151157
for (auto *Inst : llvm::reverse(InstsToRemove)) {
152158
Inst->dropAllReferences();

0 commit comments

Comments
 (0)