This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes][AArch64][ARM] Teach PromoteIntegerResult to preserve NSW/NUW flags for ADD/SUB.
AbandonedPublic

Authored by craig.topper on May 25 2023, 10:45 AM.

Details

Summary

If the promoted inputs are known to be sign/zero extended, we can
preserve these flags when we promote the operation.

Alternatively, we could forcibly sign/zero extend the input in order
to preserve the flag, but that could lead to extra code that may
not be beneficial.

Diff Detail

Event Timeline

craig.topper created this revision.May 25 2023, 10:45 AM
craig.topper requested review of this revision.May 25 2023, 10:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2023, 10:45 AM
efriedma added inline comments.May 25 2023, 11:01 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1251

Do the flags on the original node actually matter here? Unless I'm missing something, the logic you're using applies whether or not the original node was marked nsw/nuw. (e.g. the sum of two zero-extended inputs is always nuw.)

craig.topper added inline comments.May 25 2023, 11:11 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1251

Good point. At best I guess its a compile time filter. Maybe this argues that this should be in DAGCombine? Or the avgfloor optimization in SimplifyDemandedBits could be made to work use computeKnownBits/ComputeNumSignBits instead of using nuw/nsw?

nikic added inline comments.May 25 2023, 11:38 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1251

It seems like combineShiftToAVG() already computes known bits / sign bits anyway, so might as well make use of them...

bjope added a subscriber: bjope.May 25 2023, 11:50 AM
craig.topper abandoned this revision.May 31 2023, 4:39 PM