diff options
| author | Craig Topper <craig.topper@intel.com> | 2019-04-24 19:28:38 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2019-04-24 19:28:38 +0000 |
| commit | af194e938008262bb8a99514d21705eb06b953b5 (patch) | |
| tree | c37b49edc5fbd62cd45680d8abc0abd6912779c7 | |
| parent | 1591693c7cca772c3b7129d2a4f9469da208d881 (diff) | |
| download | bcm5719-llvm-af194e938008262bb8a99514d21705eb06b953b5.tar.gz bcm5719-llvm-af194e938008262bb8a99514d21705eb06b953b5.zip | |
[X86] Prevent folding a load into an AND if that AND is really a ZEXT_INREG that should use movzx.
This can save a 32-bit immediate move.
We would shrink the load and fold it if it was non-volatile, but that's trickier to check for.
llvm-svn: 359129
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/2008-09-29-VolatileBug.ll | 4 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/fold-and-shift.ll | 8 |
3 files changed, 15 insertions, 6 deletions
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp index df7f1fc524b..dd387e5e57c 100644 --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -592,6 +592,15 @@ X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { Imm->getAPIntValue().isIntN(32)) return false; + // If this really a zext_inreg that can be represented with a movzx + // instruction, prefer that. + // TODO: We could shrink the load and fold if it is non-volatile. + if (U->getOpcode() == ISD::AND && + (Imm->getAPIntValue() == UINT8_MAX || + Imm->getAPIntValue() == UINT16_MAX || + Imm->getAPIntValue() == UINT32_MAX)) + return false; + // ADD/SUB with can negate the immediate and use the opposite operation // to fit 128 into a sign extended 8 bit immediate. if ((U->getOpcode() == ISD::ADD || U->getOpcode() == ISD::SUB) && diff --git a/llvm/test/CodeGen/X86/2008-09-29-VolatileBug.ll b/llvm/test/CodeGen/X86/2008-09-29-VolatileBug.ll index ac18c2cb0bb..4c81df7de61 100644 --- a/llvm/test/CodeGen/X86/2008-09-29-VolatileBug.ll +++ b/llvm/test/CodeGen/X86/2008-09-29-VolatileBug.ll @@ -8,8 +8,8 @@ define i32 @main() nounwind { ; CHECK-LABEL: main: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movl $255, %eax -; CHECK-NEXT: andl g_407, %eax +; CHECK-NEXT: movl g_407, %eax +; CHECK-NEXT: movzbl %al, %eax ; CHECK-NEXT: pushl %eax ; CHECK-NEXT: calll func_45 ; CHECK-NEXT: addl $4, %esp diff --git a/llvm/test/CodeGen/X86/fold-and-shift.ll b/llvm/test/CodeGen/X86/fold-and-shift.ll index e14e337ea89..6db4b259971 100644 --- a/llvm/test/CodeGen/X86/fold-and-shift.ll +++ b/llvm/test/CodeGen/X86/fold-and-shift.ll @@ -5,8 +5,8 @@ define i32 @t1(i8* %X, i32 %i) { ; CHECK-LABEL: t1: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax -; CHECK-NEXT: movl $255, %ecx -; CHECK-NEXT: andl {{[0-9]+}}(%esp), %ecx +; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx +; CHECK-NEXT: movzbl %cl, %ecx ; CHECK-NEXT: movl (%eax,%ecx,4), %eax ; CHECK-NEXT: retl @@ -23,8 +23,8 @@ define i32 @t2(i16* %X, i32 %i) { ; CHECK-LABEL: t2: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax -; CHECK-NEXT: movl $65535, %ecx # imm = 0xFFFF -; CHECK-NEXT: andl {{[0-9]+}}(%esp), %ecx +; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx +; CHECK-NEXT: movzwl %cx, %ecx ; CHECK-NEXT: movl (%eax,%ecx,4), %eax ; CHECK-NEXT: retl |

