[llvm] f58e457 - [RISCV] Set ShouldSignExtI32Param in TargetLibraryInfo for riscv64.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 16:41:37 PST 2022


Author: Craig Topper
Date: 2022-12-12T16:41:28-08:00
New Revision: f58e45717d4cd6af288afb16ef092601a7352419

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

LOG: [RISCV] Set ShouldSignExtI32Param in TargetLibraryInfo for riscv64.

riscv64 sign extends signed and unsigned i32 arguments like Mips.

Based on discussion here
https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126

I'll work on returns next.

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

Added: 
    llvm/test/Transforms/InstCombine/RISCV/libcall-arg-exts.ll

Modified: 
    llvm/lib/Analysis/TargetLibraryInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 6d92eafed0c34..270fa9ccca01f 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -177,9 +177,9 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
     ShouldExtI32Param = true;
     ShouldExtI32Return = true;
   }
-  // Mips, on the other hand, needs signext on i32 parameters corresponding
-  // to both signed and unsigned ints.
-  if (T.isMIPS()) {
+  // Mips and riscv64, on the other hand, needs signext on i32 parameters
+  // corresponding to both signed and unsigned ints.
+  if (T.isMIPS() || T.isRISCV64()) {
     ShouldSignExtI32Param = true;
   }
   TLI.setShouldExtI32Param(ShouldExtI32Param);

diff  --git a/llvm/test/Transforms/InstCombine/RISCV/libcall-arg-exts.ll b/llvm/test/Transforms/InstCombine/RISCV/libcall-arg-exts.ll
new file mode 100644
index 0000000000000..559413d7973bb
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/RISCV/libcall-arg-exts.ll
@@ -0,0 +1,92 @@
+; RUN: opt < %s -passes=instcombine -S -mtriple=riscv64 | FileCheck %s
+;
+; Check that i32 arguments to generated libcalls have the proper extension
+; attributes.
+
+
+declare double @exp2(double)
+declare float @exp2f(float)
+declare fp128 @exp2l(fp128)
+
+define double @fun1(i32 %x) {
+; CHECK-LABEL: @fun1
+; CHECK: call double @ldexp
+  %conv = sitofp i32 %x to double
+  %ret = call double @exp2(double %conv)
+  ret double %ret
+}
+
+define float @fun2(i32 %x) {
+; CHECK-LABEL: @fun2
+; CHECK: call float @ldexpf
+  %conv = sitofp i32 %x to float
+  %ret = call float @exp2f(float %conv)
+  ret float %ret
+}
+
+define fp128 @fun3(i8 zeroext %x) {
+; CHECK-LABEL: @fun3
+; CHECK: call fp128 @ldexpl
+  %conv = uitofp i8 %x to fp128
+  %ret = call fp128 @exp2l(fp128 %conv)
+  ret fp128 %ret
+}
+
+ at a = common global [60 x i8] zeroinitializer, align 1
+ at b = common global [60 x i8] zeroinitializer, align 1
+declare ptr @__memccpy_chk(ptr, ptr, i32, i64, i64)
+define ptr @fun4() {
+; CHECK-LABEL: @fun4
+; CHECK: call ptr @memccpy
+  %ret = call ptr @__memccpy_chk(ptr @a, ptr @b, i32 0, i64 60, i64 -1)
+  ret ptr %ret
+}
+
+%FILE = type { }
+ at A = constant [2 x i8] c"A\00"
+declare i32 @fputs(ptr, ptr)
+define void @fun5(ptr %fp) {
+; CHECK-LABEL: @fun5
+; CHECK: call i32 @fputc
+  call i32 @fputs(ptr @A, ptr %fp)
+  ret void
+}
+
+ at empty = constant [1 x i8] zeroinitializer
+declare i32 @puts(ptr)
+define void @fun6() {
+; CHECK-LABEL: @fun6
+; CHECK: call i32 @putchar
+  call i32 @puts(ptr @empty)
+  ret void
+}
+
+ at .str1 = private constant [2 x i8] c"a\00"
+declare ptr @strstr(ptr, ptr)
+define ptr @fun7(ptr %str) {
+; CHECK-LABEL: @fun7
+; CHECK: call ptr @strchr
+  %ret = call ptr @strstr(ptr %str, ptr @.str1)
+  ret ptr %ret
+}
+
+; CHECK: declare ptr @strchr(ptr, i32 signext)
+
+ at hello = constant [14 x i8] c"hello world\5Cn\00"
+ at chp = global ptr zeroinitializer
+declare ptr @strchr(ptr, i32)
+define void @fun8(i32 %chr) {
+; CHECK-LABEL: @fun8
+; CHECK: call ptr @memchr
+  %dst = call ptr @strchr(ptr @hello, i32 %chr)
+  store ptr %dst, ptr @chp
+  ret void
+}
+
+; CHECK: declare double @ldexp(double, i32 signext)
+; CHECK: declare float @ldexpf(float, i32 signext)
+; CHECK: declare fp128 @ldexpl(fp128, i32 signext)
+; CHECK: declare ptr @memccpy(ptr noalias writeonly, ptr noalias nocapture readonly, i32 signext, i64)
+; CHECK: declare noundef i32 @fputc(i32 noundef signext, ptr nocapture noundef)
+; CHECK: declare noundef i32 @putchar(i32 noundef signext)
+; CHECK: declare ptr @memchr(ptr, i32 signext, i64)


        


More information about the llvm-commits mailing list