This is an archive of the discontinued LLVM Phabricator instance.

[X86] Teach foldMaskedShiftToScaledMask to look throw an any_extend from i32 to i64 between the and & shl
ClosedPublic

Authored by craig.topper on Apr 10 2019, 12:26 PM.

Details

Summary

foldMaskedShiftToScaledMask tries to reorder and & shl to enable the shl to fold into an LEA. But if there is an any_extend between them it doesn't work.

This patch modifies the code to look through any_extend from i32 to i64 when the and mask only uses bits that weren't from the extended part.

This will prevent a regression from D60358 caused by 64-bit SHL being narrowed to 32-bits when their upper bits aren't demanded.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 10 2019, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2019, 12:26 PM
Herald added a subscriber: hiraditya. · View Herald Transcript

Upload the right patch. The other was partial

craig.topper marked an inline comment as done.Apr 10 2019, 12:30 PM
craig.topper added inline comments.
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
1877 ↗(On Diff #194569)

This is a little hard to see here, but 3 of the functions look for SRL and one looks for SHL. But we used to check for either SHL or SRL earlier. Now that we also need to consider ANY_EXTEND. I've removed the early check for SHL/SHR. Covered the 3 functions that use SRL with a check for that. Each of the functions all check ISD::SRL internally, but expect the input to be passed as X. This could probably be cleaned up a little though one of the functions does have 2 callers.

The SHL function is now unqualified and will check for ANY_EXTEND/SHL and create X internally.

spatel accepted this revision.Apr 10 2019, 1:53 PM

LGTM - thanks!

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
1389 ↗(On Diff #194569)

We have -> If we have

1391 ↗(On Diff #194569)

behind -> beside?

llvm/test/CodeGen/X86/fold-and-shift-x86_64.ll
79 ↗(On Diff #194569)

Remove stale comment

This revision is now accepted and ready to land.Apr 10 2019, 1:53 PM
This revision was automatically updated to reflect the committed changes.