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
2532

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
2532

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
2529–2533

IRBuilder is unused?

2531

style: No branches around single expression if

2536

ibid

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
2529–2533

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

2531

It covers multiple lines

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
2538

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
2538

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
2538

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
390

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