Skip to content

Commit 768c324

Browse files
amy-kwantru
authored andcommitted
[AIX] Handle arbitrary sized integers when lowering formal arguments passed on the stack (#149351)
When arbitrary sized (non-simple type, or non-power of two types) integers are passed on the stack, these integers are not handled when lowering formal arguments on AIX as we always assume we will encounter simple type integers. However, it is possible for frontends to generate arbitrary sized immediate values in IR. Specifically in rustc, it will generate an integer value in LLVM IR for small structures that are less than a pointer size, which is done for optimization purposes for the Rust ABI. For example, if a Rust structure of three characters is passed into function on the stack, ``` struct my_struct { field1: u8, field2: u8, field3: u8, } ``` This will generate an `i24` type in LLVM IR. Currently, it is not obvious for the backend to distinguish an integer versus something that wasn't an integer to begin with (such as a struct), and the latter case would not have an extend on the parameter. Thus, this PR allows us to perform a truncation and extend on integers, both non-simple and simple types. (cherry picked from commit f48a8da)
1 parent 3290ca0 commit 768c324

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7296,9 +7296,17 @@ SDValue PPCTargetLowering::LowerFormalArguments_AIX(
72967296
if (!ArgVT.isVector() && !ValVT.isVector() && ArgVT.isInteger() &&
72977297
ValVT.isInteger() &&
72987298
ArgVT.getScalarSizeInBits() < ValVT.getScalarSizeInBits()) {
7299-
SDValue ArgValueTrunc = DAG.getNode(
7300-
ISD::TRUNCATE, dl, ArgVT.getSimpleVT() == MVT::i1 ? MVT::i8 : ArgVT,
7301-
ArgValue);
7299+
// It is possible to have either real integer values
7300+
// or integers that were not originally integers.
7301+
// In the latter case, these could have came from structs,
7302+
// and these integers would not have an extend on the parameter.
7303+
// Since these types of integers do not have an extend specified
7304+
// in the first place, the type of extend that we do should not matter.
7305+
EVT TruncatedArgVT = ArgVT.isSimple() && ArgVT.getSimpleVT() == MVT::i1
7306+
? MVT::i8
7307+
: ArgVT;
7308+
SDValue ArgValueTrunc =
7309+
DAG.getNode(ISD::TRUNCATE, dl, TruncatedArgVT, ArgValue);
73027310
SDValue ArgValueExt =
73037311
ArgSignExt ? DAG.getSExtOrTrunc(ArgValueTrunc, dl, ValVT)
73047312
: DAG.getZExtOrTrunc(ArgValueTrunc, dl, ValVT);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc --verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff \
3+
; RUN: -ppc-asm-full-reg-names -mcpu=pwr8 < %s | \
4+
; RUN: FileCheck %s --check-prefixes=CHECK,CHECK32
5+
; RUN: llc --verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \
6+
; RUN: -ppc-asm-full-reg-names -mcpu=pwr8 < %s | \
7+
; RUN: FileCheck %s --check-prefixes=CHECK,CHECK64
8+
9+
define ptr @lower_args(ptr %_0, i32 %0, i32 %1, i32 %2, i32 %3, ptr %4, ptr %5, i64 %6, i24 %7) {
10+
; CHECK-LABEL: lower_args:
11+
; CHECK: # %bb.0: # %entry
12+
; CHECK-NEXT: blr
13+
entry:
14+
ret ptr %_0
15+
}
16+
17+
define i32 @lower_args_withops_zeroext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i24 %i) {
18+
; CHECK32-LABEL: lower_args_withops_zeroext:
19+
; CHECK32: # %bb.0: # %entry
20+
; CHECK32-NEXT: lwz r3, 56(r1)
21+
; CHECK32-NEXT: addi r3, r3, 255
22+
; CHECK32-NEXT: clrlwi r3, r3, 8
23+
; CHECK32-NEXT: blr
24+
;
25+
; CHECK64-LABEL: lower_args_withops_zeroext:
26+
; CHECK64: # %bb.0: # %entry
27+
; CHECK64-NEXT: lwz r3, 116(r1)
28+
; CHECK64-NEXT: addi r3, r3, 255
29+
; CHECK64-NEXT: clrldi r3, r3, 40
30+
; CHECK64-NEXT: blr
31+
entry:
32+
%0 = add i24 %i, 255
33+
%1 = zext i24 %0 to i32
34+
ret i32 %1
35+
}
36+
37+
define i32 @lower_args_withops_signext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i24 signext %i) {
38+
; CHECK32-LABEL: lower_args_withops_signext:
39+
; CHECK32: # %bb.0: # %entry
40+
; CHECK32-NEXT: lwz r3, 56(r1)
41+
; CHECK32-NEXT: slwi r3, r3, 8
42+
; CHECK32-NEXT: srawi r3, r3, 8
43+
; CHECK32-NEXT: slwi r3, r3, 8
44+
; CHECK32-NEXT: addi r3, r3, 22272
45+
; CHECK32-NEXT: srawi r3, r3, 8
46+
; CHECK32-NEXT: blr
47+
;
48+
; CHECK64-LABEL: lower_args_withops_signext:
49+
; CHECK64: # %bb.0: # %entry
50+
; CHECK64-NEXT: lwz r3, 116(r1)
51+
; CHECK64-NEXT: slwi r3, r3, 8
52+
; CHECK64-NEXT: srawi r3, r3, 8
53+
; CHECK64-NEXT: addi r3, r3, 87
54+
; CHECK64-NEXT: sldi r3, r3, 40
55+
; CHECK64-NEXT: sradi r3, r3, 40
56+
; CHECK64-NEXT: blr
57+
entry:
58+
%0 = add i24 %i, 87
59+
%1 = sext i24 %0 to i32
60+
ret i32 %1
61+
}

0 commit comments

Comments
 (0)