This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Fold fneg (ldexp x, n) -> ldexp (fneg x), n
ClosedPublic

Authored by arsenm on Jul 28 2023, 4:09 PM.

Diff Detail

Event Timeline

arsenm created this revision.Jul 28 2023, 4:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2023, 4:09 PM
arsenm requested review of this revision.Jul 28 2023, 4:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2023, 4:09 PM
Herald added a subscriber: wdng. · View Herald Transcript
goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2562–2563

Seems like 2 changes at once? The change to oneuse checks of (fneg (fmul/fdiv)) and the new transform. Maybe split?

llvm/test/Transforms/InstCombine/fneg.ll
989

Can you precommit the tests?

arsenm updated this revision to Diff 546265.Aug 1 2023, 4:43 PM
arsenm marked an inline comment as done.

Precommit test

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2562–2563

It's not behaviorally changing, it's just avoiding repeating it 3x

goldstein.w.n added inline comments.Aug 2 2023, 9:11 AM
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2566

style: No branches around single expression if

2571

ibid

2579–2588

IRBuilder is unused?

llvm/test/Transforms/InstCombine/fneg.ll
989

This was erroneously marked done?

arsenm added inline comments.Aug 2 2023, 11:42 AM
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2566

It covers multiple lines

2579–2588

It's a flag guard, it only does anything on destruct. The actual builder is the member

jcranmer-intel added inline comments.Aug 2 2023, 2:20 PM
llvm/test/Transforms/InstCombine/fneg.ll
840

The optimization doesn't seem to be kicking in for these tests?

arsenm updated this revision to Diff 546608.Aug 2 2023, 2:22 PM

Fix diff after test split

arsenm updated this revision to Diff 549419.Aug 11 2023, 8:32 AM

Rebase and ping

goldstein.w.n added inline comments.Aug 11 2023, 1:38 PM
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2573

Doesn't exponent need to by odd for this? I.e

-(X ^ 2) != ((-X) ^ 2).

arsenm added inline comments.Aug 11 2023, 1:55 PM
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2573

It’s not a square, it’s X * 2^N

goldstein.w.n accepted this revision.Aug 11 2023, 2:44 PM

LGTM.

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
2573

Err yeah :/

This revision is now accepted and ready to land.Aug 11 2023, 2:44 PM
foad added inline comments.Aug 15 2023, 2:15 AM
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
395

Function needs a comment and a better name, since it doesn't just handle fmul and fdiv now.