[llvm-commits] [llvm] r81814 - in /llvm/trunk: lib/Target/X86/X86Instr64bit.td test/CodeGen/X86/cmov-zext.ll
Dan Gohman
gohman at apple.com
Mon Sep 14 17:14:11 PDT 2009
Author: djg
Date: Mon Sep 14 19:14:11 2009
New Revision: 81814
URL: http://llvm.org/viewvc/llvm-project?rev=81814&view=rev
Log:
On x86-64, the 32-bit cmov doesn't actually clear the high 32-bit of
its result if the condition is false.
Added:
llvm/trunk/test/CodeGen/X86/cmov-zext.ll
Modified:
llvm/trunk/lib/Target/X86/X86Instr64bit.td
Modified: llvm/trunk/lib/Target/X86/X86Instr64bit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Instr64bit.td?rev=81814&r1=81813&r2=81814&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86Instr64bit.td (original)
+++ llvm/trunk/lib/Target/X86/X86Instr64bit.td Mon Sep 14 19:14:11 2009
@@ -387,13 +387,15 @@
[(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
// Any instruction that defines a 32-bit result leaves the high half of the
-// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
-// be copying from a truncate, but any other 32-bit operation will zero-extend
+// register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
+// be copying from a truncate. And x86's cmov doesn't do anything if the
+// condition is false. But any other 32-bit operation will zero-extend
// up to 64 bits.
def def32 : PatLeaf<(i32 GR32:$src), [{
return N->getOpcode() != ISD::TRUNCATE &&
N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
- N->getOpcode() != ISD::CopyFromReg;
+ N->getOpcode() != ISD::CopyFromReg &&
+ N->getOpcode() != X86ISD::CMOV;
}]>;
// In the case of a 32-bit def that is known to implicitly zero-extend,
Added: llvm/trunk/test/CodeGen/X86/cmov-zext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cmov-zext.ll?rev=81814&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cmov-zext.ll (added)
+++ llvm/trunk/test/CodeGen/X86/cmov-zext.ll Mon Sep 14 19:14:11 2009
@@ -0,0 +1,19 @@
+; RUN: llc < %s -march=x86-64 | FileCheck %s
+
+; x86's 32-bit cmov doesn't clobber the high 32 bits of the destination
+; if the condition is false. An explicit zero-extend (movl) is needed
+; after the cmov.
+
+; CHECK: cmovne %edi, %esi
+; CHECK-NEXT: movl %esi, %edi
+
+declare void @bar(i64) nounwind
+
+define void @foo(i64 %a, i64 %b, i1 %p) nounwind {
+ %c = trunc i64 %a to i32
+ %d = trunc i64 %b to i32
+ %e = select i1 %p, i32 %c, i32 %d
+ %f = zext i32 %e to i64
+ call void @bar(i64 %f)
+ ret void
+}
More information about the llvm-commits
mailing list