This is an archive of the discontinued LLVM Phabricator instance.

[Reassociate] Keep flags for more unchanged operations
ClosedPublic

Authored by dmgreen on Jul 1 2023, 1:58 PM.

Details

Summary

Reassociation destroys nsw/nuw flags from BinOps that are changed. If the expression in at the end of a tree that was altered, but didn't change itself the flags do not need to be removed though. For example, if %a, %b and %c are reassociated in

%x = add nsw i32 %a, %c
%y = add nsw i32 %x, %b
%z = add nsw i32 %y, %d

The value of %y and so add %y %d remains the same, and %z needn't drop the nsw flags.
https://alive2.llvm.org/ce/z/_juAiV

Diff Detail

Event Timeline

dmgreen created this revision.Jul 1 2023, 1:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 1:58 PM
dmgreen requested review of this revision.Jul 1 2023, 1:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 1:58 PM
nikic accepted this revision.Jul 2 2023, 1:21 AM

LGTM

llvm/lib/Transforms/Scalar/Reassociate.cpp
832–833

As a side note, I don't think we need to do this bit either for unchanged expressions.

This revision is now accepted and ready to land.Jul 2 2023, 1:21 AM
This revision was automatically updated to reflect the committed changes.