[PATCH] D11637: X86: Set AMD OpenCL libfunc name overrides

Matt Arsenault Matthew.Arsenault at amd.com
Thu Jul 30 01:54:00 PDT 2015


arsenm created this revision.
arsenm added a subscriber: llvm-commits.

http://reviews.llvm.org/D11637

Files:
  lib/Target/X86/X86ISelLowering.cpp
  lib/Target/X86/X86Subtarget.h
  test/CodeGen/X86/amdopencl.ll

Index: test/CodeGen/X86/amdopencl.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/amdopencl.ll
@@ -0,0 +1,49 @@
+; RUN: llc -march=x86 -mtriple=i686-pc-linux-amdopencl < %s | FileCheck -check-prefix=X86 -check-prefix=COMMON %s
+; RUN: llc -march=x86-64 -mtriple=x86_64-pc-linux-amdopencl < %s | FileCheck -check-prefix=X86_64 -check-prefix=COMMON %s
+
+; COMMON-LABEL: {{^}}test_amdrt_cvt_f32_to_u64:
+; X86: calll __amdrt_cvt_f32_to_u64
+; X86_64-NOT: __amdrt_cvt_f32_to_u64
+define i64 @test_amdrt_cvt_f32_to_u64(float %x) {
+  %cvt = fptoui float %x to i64
+  ret i64 %cvt
+}
+
+; COMMON-LABEL: {{^}}test_amdrt_cvt_f64_to_u64:
+; X86: calll __amdrt_cvt_f64_to_u64
+; X86_64-NOT: __amdrt_cvt_f64_to_u64
+define i64 @test_amdrt_cvt_f64_to_u64(double %x) {
+  %cvt = fptoui double %x to i64
+  ret i64 %cvt
+}
+
+; COMMON-LABEL: {{^}}test_amdrt_div_i64:
+; X86: calll __amdrt_div_i64
+; X86_64-NOT: __amdrt_div_i64
+define i64 @test_amdrt_div_i64(i64 %x, i64 %y) {
+  %div = sdiv i64 %x, %y
+  ret i64 %div
+}
+
+; COMMON-LABEL: {{^}}test_amdrt_div_u64:
+; X86: calll __amdrt_div_u64
+; X86_64-NOT: __amdrt_div_u64
+define i64 @test_amdrt_div_u64(i64 %x, i64 %y) {
+  %div = udiv i64 %x, %y
+  ret i64 %div
+}
+
+; COMMON-LABEL: {{^}}test_amdrt_mod_i64:
+; X86: calll __amdrt_mod_i64
+; X86_64-NOT: __amdrt_mod_i64
+define i64 @test_amdrt_mod_i64(i64 %x, i64 %y) {
+  %rem = srem i64 %x, %y
+  ret i64 %rem
+}
+
+; COMMON-LABEL: {{^}}test_amdrt_mod_u64:
+; X86_64-NOT: __amdrt_mod_u64
+define i64 @test_amdrt_mod_u64(i64 %x, i64 %y) {
+  %rem = urem i64 %x, %y
+  ret i64 %rem
+}
\ No newline at end of file
Index: lib/Target/X86/X86Subtarget.h
===================================================================
--- lib/Target/X86/X86Subtarget.h
+++ lib/Target/X86/X86Subtarget.h
@@ -430,6 +430,10 @@
     return !In64BitMode && (isTargetCygMing() || isTargetKnownWindowsMSVC());
   }
 
+  bool isTargetAMDOpenCL() const {
+    return TargetTriple.getEnvironment() == Triple::AMDOpenCL;
+  }
+
   bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
   bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -1689,6 +1689,15 @@
     setOperationAction(ISD::UDIVREM, MVT::i128, Custom);
   }
 
+  if (!Subtarget->is64Bit() && Subtarget->isTargetAMDOpenCL()) {
+    setLibcallName(RTLIB::FPTOUINT_F32_I64, "__amdrt_cvt_f32_to_u64");
+    setLibcallName(RTLIB::FPTOUINT_F64_I64, "__amdrt_cvt_f64_to_u64");
+    setLibcallName(RTLIB::SDIV_I64, "__amdrt_div_i64");
+    setLibcallName(RTLIB::UDIV_I64, "__amdrt_div_u64");
+    setLibcallName(RTLIB::SREM_I64, "__amdrt_mod_i64");
+    setLibcallName(RTLIB::UREM_I64, "__amdrt_mod_u64");
+  }
+
   // We have target-specific dag combine patterns for the following nodes:
   setTargetDAGCombine(ISD::VECTOR_SHUFFLE);
   setTargetDAGCombine(ISD::EXTRACT_VECTOR_ELT);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11637.31006.patch
Type: text/x-patch
Size: 3158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150730/462b7d8e/attachment.bin>


More information about the llvm-commits mailing list