This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner][X86][PowerPC][ARM][AMDGPU][Sparc] Replace (sub C, X) with (xor X, C) if there is no chance of a borrow during the subtraction.
AbandonedPublic

Authored by craig.topper on Jun 24 2018, 2:59 PM.

Details

Summary

This is definitely helpful on X86 where there is no subtract from an immediate instruction. So turning it into xor allows the immediate to fold.

Some of the PowerPC changes are regressions, but we may be able to fix them with other folds.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 24 2018, 2:59 PM

Looks like a generally good fold to me - prefer bitwise logic because that's the cheapest ALU op possible.

Adding some PowerPC reviewers to see if they're ok with the regression or if that must be fixed first.

arsenm added a subscriber: arsenm.Jun 25 2018, 8:40 AM
arsenm added inline comments.
test/CodeGen/AMDGPU/ds-sub-offset.ll
26

This is worse in terms of code size, so ideally there would be an undo-combine for this during selection

craig.topper abandoned this revision.Jun 27 2018, 9:03 AM

I made an X86 specific change for this directly in isel. Abandoning.