Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[X86] Don't zero/sign-extend i1, i8, or i16 return values to 32 bits …
…(PR22532) This matches GCC and MSVC's behaviour, and saves on code size. We were already not extending i1 return values on x86_64 after r127766. This takes that patch further by applying it to x86 target as well, and also for i8 and i16. The ABI docs have been unclear about the required behaviour here. The new i386 psABI [1] clearly states (Table 2.4, page 14) that i1, i8, and i16 return vales do not need to be extended beyond 8 bits. The x86_64 ABI doc is being updated to say the same [2]. Differential Revision: http://reviews.llvm.org/D16907 [1]. https://01.org/sites/default/files/file_attach/intel386-psabi-1.0.pdf [2]. https://groups.google.com/d/msg/x86-64-abi/E8O33onbnGQ/_RFWw_ixDQAJ llvm-svn: 260133
- Loading branch information
Showing
19 changed files
with
207 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
; RUN: llc < %s -march=x86 | grep mov | count 1 | ||
; RUN: llc < %s -march=x86-64 | grep mov | count 1 | ||
; RUN: llc < %s -mtriple=x86_64-linux-gnux32 | grep mov | count 1 | ||
; RUN: llc < %s -march=x86 | FileCheck %s -check-prefix=X86 | ||
; RUN: llc < %s -march=x86-64 | FileCheck %s -check-prefix=X64 | ||
; RUN: llc < %s -mtriple=x86_64-linux-gnux32 | FileCheck %s -check-prefix=X32 | ||
|
||
define zeroext i8 @foo() nounwind ssp { | ||
entry: | ||
%0 = tail call zeroext i16 (...) @bar() nounwind | ||
%1 = lshr i16 %0, 8 | ||
%2 = trunc i16 %1 to i8 | ||
ret i8 %2 | ||
|
||
; X86-LABEL: foo | ||
; X86: calll | ||
; X86-NEXT: movb %ah, %al | ||
; X86-NEXT: addl $12, %esp | ||
; X86-NEXT: retl | ||
|
||
; X64-LABEL: foo | ||
; X64: callq | ||
; X64-NEXT: shrl $8, %eax | ||
; X64-NEXT: popq | ||
; X64-NEXT: retq | ||
|
||
; X32-LABEL: foo | ||
; X32: callq | ||
; X32-NEXT: shrl $8, %eax | ||
; X32-NEXT: popq | ||
; X32-NEXT: retq | ||
} | ||
|
||
declare zeroext i16 @bar(...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
; RUN: llc < %s -mtriple=i686-unknown-linux-gnu | FileCheck %s | ||
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s | ||
|
||
|
||
@x = common global i32 0, align 4 | ||
|
||
define zeroext i1 @unsigned_i1() { | ||
entry: | ||
%0 = load i32, i32* @x | ||
%cmp = icmp eq i32 %0, 42 | ||
ret i1 %cmp | ||
|
||
; Unsigned i1 return values are not extended. | ||
; CHECK-LABEL: unsigned_i1: | ||
; CHECK: cmp | ||
; CHECK-NEXT: sete | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
define zeroext i8 @unsigned_i8() { | ||
entry: | ||
%0 = load i32, i32* @x | ||
%cmp = icmp eq i32 %0, 42 | ||
%retval = zext i1 %cmp to i8 | ||
ret i8 %retval | ||
|
||
; Unsigned i8 return values are not extended. | ||
; CHECK-LABEL: unsigned_i8: | ||
; CHECK: cmp | ||
; CHECK-NEXT: sete | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
define signext i8 @signed_i8() { | ||
entry: | ||
%0 = load i32, i32* @x | ||
%cmp = icmp eq i32 %0, 42 | ||
%retval = zext i1 %cmp to i8 | ||
ret i8 %retval | ||
|
||
; Signed i8 return values are not extended. | ||
; CHECK-LABEL: signed_i8: | ||
; CHECK: cmp | ||
; CHECK-NEXT: sete | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
@a = common global i16 0 | ||
@b = common global i16 0 | ||
define zeroext i16 @unsigned_i16() { | ||
entry: | ||
%0 = load i16, i16* @a | ||
%1 = load i16, i16* @b | ||
%add = add i16 %1, %0 | ||
ret i16 %add | ||
|
||
; i16 return values are not extended. | ||
; CHECK-LABEL: unsigned_i16: | ||
; CHECK: movw | ||
; CHECK-NEXT: addw | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
|
||
define i32 @use_i1() { | ||
entry: | ||
%0 = call i1 @unsigned_i1(); | ||
%1 = zext i1 %0 to i32 | ||
ret i32 %1 | ||
|
||
; The high 24 bits of %eax from a function returning i1 are undefined. | ||
; CHECK-LABEL: use_i1: | ||
; CHECK: call | ||
; CHECK-NEXT: movzbl | ||
; CHECK-NEXT: {{pop|add}} | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
define i32 @use_i8() { | ||
entry: | ||
%0 = call i8 @unsigned_i8(); | ||
%1 = zext i8 %0 to i32 | ||
ret i32 %1 | ||
|
||
; The high 24 bits of %eax from a function returning i8 are undefined. | ||
; CHECK-LABEL: use_i8: | ||
; CHECK: call | ||
; CHECK-NEXT: movzbl | ||
; CHECK-NEXT: {{pop|add}} | ||
; CHECK-NEXT: ret | ||
} | ||
|
||
define i32 @use_i16() { | ||
entry: | ||
%0 = call i16 @unsigned_i16(); | ||
%1 = zext i16 %0 to i32 | ||
ret i32 %1 | ||
|
||
; The high 16 bits of %eax from a function returning i16 are undefined. | ||
; CHECK-LABEL: use_i16: | ||
; CHECK: call | ||
; CHECK-NEXT: movzwl | ||
; CHECK-NEXT: {{pop|add}} | ||
; CHECK-NEXT: ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.