This is an archive of the discontinued LLVM Phabricator instance.

[X86] Teach convertToThreeAddress to handle SUB with immediate
ClosedPublic

Authored by craig.topper on Jul 11 2019, 10:34 AM.

Details

Summary

We mostly avoid sub with immediate but there are a couple cases that can create them. One is the add 128, %rax -> sub -128, %rax trick in isel. The other is when a SUB immediate gets created for a compare where both the flags and the subtract value is used. If we are unable to linearize the SelectionDAG to satisfy the flag user and the sub result user from the same instruction, we will clone the sub immediate for the two uses. The one that produces flags will eventually become a compare. The other will have its flag output dead, and could then be considered for LEA creation.

I added additional test cases to add.ll to show the the sub -128 trick gets converted to LEA and a case where we don't need to convert it.

This showed up in the current codegen for PR42571.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 11 2019, 10:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2019, 10:34 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
craig.topper edited the summary of this revision. (Show Details)Jul 11 2019, 10:35 AM

please can you pre-commit the additional tests?

Rebase after commiting tests

This revision is now accepted and ready to land.Jul 12 2019, 12:04 AM
This revision was automatically updated to reflect the committed changes.