This is an archive of the discontinued LLVM Phabricator instance.

[DAG] Fold (abs (sign_extend_inreg x)) -> (zero_extend (abs (truncate x))) (PR43370)
ClosedPublic

Authored by RKSimon on Oct 23 2022, 11:18 AM.

Details

Summary

If the upper half of an abs() is all sign bits, then we can perform the abs() using just the lower half and then zero extend.

I've limited the DAG combine to only sign_extend_inreg (and free truncate/zero_extend) to minimise any later promotion issues, but for legalization a similar fold can use ComputeNumSignBits to be more aggressive.

Alive2: https://alive2.llvm.org/ce/z/y32fS4

Fixes #43370

Diff Detail

Event Timeline

RKSimon created this revision.Oct 23 2022, 11:18 AM
RKSimon requested review of this revision.Oct 23 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 11:18 AM
This revision is now accepted and ready to land.Oct 23 2022, 8:47 PM