This is an archive of the discontinued LLVM Phabricator instance.

fix a logic bug in x86 vector codegen: sext (zext (x) ) != sext (x) (PR20472)
AbandonedPublic

Authored by spatel on Aug 14 2014, 9:55 AM.

Details

Summary

As shown in InstCombine: sext ( zext ( x ) ) -> zext ( x ).

The code in X86ISelLowering that this patch proposes to remove mistakenly implemented the transform as:
sext ( zext ( x ) ) -> sext ( x )

Ie, what should be a zext output was turned into a sext.

I want to believe that the logic in the original patch has some value as an optimization for some other case and it's just not in the right place here. But the test cases from:
http://llvm.org/viewvc/llvm-project?view=revision&revision=177421
don't provide any evidence.

We just have miscompile bugs:
http://llvm.org/bugs/show_bug.cgi?id=20472 (please see this one for more of my analysis)
http://llvm.org/bugs/show_bug.cgi?id=18054

The testcases that I've added here confirm that we (1) don't remove a zext op that is necessary and (2) generate a pmovz instead of punpck if SSE4.1 is available. Although pmovz is 1 byte longer, it allows folding of the load, and so saves 3 bytes overall.

We don't need to call LowerVectorIntExtend() from LowerSIGN_EXTEND_INREG() to get this codegen either - that is already handled in NormalizeVectorShuffle().

Diff Detail

Event Timeline

spatel updated this revision to Diff 12515.Aug 14 2014, 9:55 AM
spatel retitled this revision from to fix a logic bug in x86 vector codegen: sext (zext (x) ) != sext (x) (PR20472).
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: chandlerc, nadav, rafael, hliao.
spatel added a subscriber: Unknown Object (MLST).
spatel abandoned this revision.Aug 14 2014, 10:01 AM

Abandoning - forgot to add llvm-commits list initially, so I've created a new patch.