This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner][X86][PowerPC] Teach visitSIGN_EXTEND_INREG to fold (sext_in_reg (aext/sext x)) -> (sext x) when x has more than 1 sign bit and the sext_inreg is from one of them.
ClosedPublic

Authored by craig.topper on Dec 29 2018, 1:54 PM.

Details

Summary

If x has multiple sign bits than it doesn't matter which one we extend from so we can sext from x's msb instead.

The X86 setcc-combine.ll changes are a little weird, but probably not much of a performance difference. It appears we ended up with a (sext_inreg (aext (trunc (extractelt)))) after type legalization. The sext_inreg+aext now gets optimized by this combine to leave (sext (trunc (extractelt))). Then we visit the trunc before we visit the sext. This ends up changing the truncate to an extractvectorelt from a bitcasted vector. I can see a couple ways to fix this. Early exit from visitTRUNCATE if its used by a sext similar to what is done for aext. This is tricky because we aren't always able to optimize a sext+trunc. The other option is to change type legalization to promote extractvectorelt inputs and result type simultaneously. If we promote the result first we can temporarily have an extractvectorelt with a result type we never really wanted.

Diff Detail

Event Timeline

craig.topper created this revision.Dec 29 2018, 1:54 PM
hfinkel added inline comments.
test/CodeGen/PowerPC/f128-truncateNconv.ll
358

This test-case change looks technically correct (note that this will change behavior of programs with UB (if the value being converted to an integer wasn't really representable in the smaller integer size)).

RKSimon added inline comments.Dec 31 2018, 7:55 AM
test/CodeGen/X86/setcc-combine.ll
2

Please can you replace the -mcpu with -mattr=+sse2/sse41 variants to prove that the codegen changes are different if we have suitable pextrd support?

Rebase. Looks like this is a regression on sse4.1 on setcc-combine.ll. I'll work on a follow up patch for that.

RKSimon accepted this revision.Jan 2 2019, 2:37 AM

LGTM thanks

This revision is now accepted and ready to land.Jan 2 2019, 2:37 AM