[clang] b2638a7 - [clang] Do not extend i8 return values to i16 on AVR.

Ben Shi via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 21 04:34:09 PST 2022


Author: Ben Shi
Date: 2022-12-21T20:33:49+08:00
New Revision: b2638a7a34d97066caa234999055bf580cbab02f

URL: https://github.com/llvm/llvm-project/commit/b2638a7a34d97066caa234999055bf580cbab02f
DIFF: https://github.com/llvm/llvm-project/commit/b2638a7a34d97066caa234999055bf580cbab02f.diff

LOG: [clang] Do not extend i8 return values to i16 on AVR.

Reviewed By: Miss_Grape, aykevl

Differential Revision: https://reviews.llvm.org/D139908

Added: 
    

Modified: 
    clang/lib/CodeGen/TargetInfo.cpp
    clang/test/CodeGen/avr/avr-builtins.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 98b54dfb1651f..aec170ae55706 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8445,6 +8445,10 @@ class AVRABIInfo : public DefaultABIInfo {
       LargeRet = true;
       return getNaturalAlignIndirect(Ty);
     }
+    // An i8 return value should not be extended to i16, since AVR has 8-bit
+    // registers.
+    if (Ty->isIntegralOrEnumerationType() && getContext().getTypeSize(Ty) <= 8)
+      return ABIArgInfo::getDirect();
     // Otherwise we follow the default way which is compatible.
     return DefaultABIInfo::classifyReturnType(Ty);
   }

diff  --git a/clang/test/CodeGen/avr/avr-builtins.c b/clang/test/CodeGen/avr/avr-builtins.c
index bdecff3fc38a8..7c2c424848080 100644
--- a/clang/test/CodeGen/avr/avr-builtins.c
+++ b/clang/test/CodeGen/avr/avr-builtins.c
@@ -8,7 +8,7 @@ unsigned char bitrev8(unsigned char data) {
     return __builtin_bitreverse8(data);
 }
 
-// CHECK: define{{.*}} zeroext i8 @bitrev8
+// CHECK: define{{.*}} i8 @bitrev8
 // CHECK: i8 @llvm.bitreverse.i8(i8
 
 unsigned int bitrev16(unsigned int data) {
@@ -35,7 +35,7 @@ unsigned char rotleft8(unsigned char x, unsigned char y) {
     return __builtin_rotateleft8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotleft8
+// CHECK: define{{.*}} i8 @rotleft8
 // CHECK: i8 @llvm.fshl.i8(i8
 
 unsigned int rotleft16(unsigned int x, unsigned int y) {
@@ -62,7 +62,7 @@ unsigned char rotright8(unsigned char x, unsigned char y) {
     return __builtin_rotateright8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotright8
+// CHECK: define{{.*}} i8 @rotright8
 // CHECK: i8 @llvm.fshr.i8(i8
 
 unsigned int rotright16(unsigned int x, unsigned int y) {


        


More information about the cfe-commits mailing list