This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Fold fdiv nnan x, 0 -> copysign(inf, x)
ClosedPublic

Authored by arsenm on Oct 17 2022, 11:19 AM.

Diff Detail

Event Timeline

arsenm created this revision.Oct 17 2022, 11:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 11:19 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Oct 17 2022, 11:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 11:19 AM
Herald added a subscriber: wdng. · View Herald Transcript
kpn added a comment.Oct 17 2022, 12:07 PM

Precommit tests?

arsenm updated this revision to Diff 468289.Oct 17 2022, 12:36 PM
arsenm edited the summary of this revision. (Show Details)

Rebase on baseline tests

kpn added inline comments.Oct 17 2022, 12:52 PM
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1406

Is this part of a future change? I'm wondering if it belongs in this patch.

1427

This looks fine to me, but I'll let Sanjay give the word. I've never worked in InstCombine.

arsenm added inline comments.Oct 17 2022, 12:56 PM
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1406

No, this needed to move into the class for replaceInstUsesWith

spatel added inline comments.Oct 17 2022, 2:21 PM
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1420

If we're changing this function from static to a member of InstCombinerImpl, then we can use the already instantiated IRBuilder for the class, so it'd be something like:

CallInst *CopySign = Builder.CreateIntrinsic(...);

Alternatively, we can leave this function static and use the raw creator API:

Function *F = Intrinsic::getDeclaration(I.getModule(), Intrinsic::copysign, C->getType());
return CallInst::Create(F, {Infinity, I.getOperand(0)});
arsenm updated this revision to Diff 473712.Nov 7 2022, 9:16 AM

Use existing IRBuilder

spatel accepted this revision.Nov 7 2022, 11:14 AM

LGTM

This revision is now accepted and ready to land.Nov 7 2022, 11:14 AM