[X86] When promoting i16 compare with immediate to i32, try to use sign_extend for...
authorCraig Topper <craig.topper@intel.com>
Mon, 10 Jun 2019 04:50:12 +0000 (04:50 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 10 Jun 2019 04:50:12 +0000 (04:50 +0000)
commit9000a72a4b723513499d97fb88a25a860132c323
tree1bb2656bd99d6f33943db2fb633a50292b13da62
parentceb807bbbcb5e514b3a683141da506f36ed9e44c
[X86] When promoting i16 compare with immediate to i32, try to use sign_extend for eq/ne if the input is truncated from a type with enough sign its.

Summary:
Our default behavior is to use sign_extend for signed comparisons and zero_extend for everything else. But for equality we have the freedom to use either extension. If we can prove the input has been truncated from something with enough sign bits, we can use sign_extend instead and let DAG combine optimize it out. A similar rule is used by type legalization in LegalizeIntegerTypes.

This gets rid of the movzx in PR42189. The immediate will still take 4 bytes instead of the 2 bytes plus 0x66 prefix a cmp di, 32767 would get, but it avoids a length changing prefix.

Reviewers: RKSimon, spatel, xbolva00

Reviewed By: xbolva00

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63032

llvm-svn: 362920
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/cmp.ll