Skip to content

Commit c61881e

Browse files
committed
Merge 81814 from mainline.
On x86-64, the 32-bit cmov doesn't actually clear the high 32-bit of its result if the condition is false. llvm-svn: 81977
1 parent c47a943 commit c61881e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

llvm/lib/Target/X86/X86Instr64bit.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
363363
[(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
364364

365365
// Any instruction that defines a 32-bit result leaves the high half of the
366-
// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
367-
// be copying from a truncate, but any other 32-bit operation will zero-extend
366+
// register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
367+
// be copying from a truncate. And x86's cmov doesn't do anything if the
368+
// condition is false. But any other 32-bit operation will zero-extend
368369
// up to 64 bits.
369370
def def32 : PatLeaf<(i32 GR32:$src), [{
370371
return N->getOpcode() != ISD::TRUNCATE &&
371372
N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
372-
N->getOpcode() != ISD::CopyFromReg;
373+
N->getOpcode() != ISD::CopyFromReg &&
374+
N->getOpcode() != X86ISD::CMOV;
373375
}]>;
374376

375377
// In the case of a 32-bit def that is known to implicitly zero-extend,

llvm/test/CodeGen/X86/cmov-zext.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc < %s -march=x86-64 | FileCheck %s
2+
3+
; x86's 32-bit cmov doesn't clobber the high 32 bits of the destination
4+
; if the condition is false. An explicit zero-extend (movl) is needed
5+
; after the cmov.
6+
7+
; CHECK: cmovne %edi, %esi
8+
; CHECK-NEXT: movl %esi, %edi
9+
10+
declare void @bar(i64) nounwind
11+
12+
define void @foo(i64 %a, i64 %b, i1 %p) nounwind {
13+
%c = trunc i64 %a to i32
14+
%d = trunc i64 %b to i32
15+
%e = select i1 %p, i32 %c, i32 %d
16+
%f = zext i32 %e to i64
17+
call void @bar(i64 %f)
18+
ret void
19+
}

0 commit comments

Comments
 (0)