r341678 - [X86] Modify addcarry/subborrow builtins to emit an 2 result and intrinsic and an store instruction.

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 7 09:58:57 PDT 2018


Author: ctopper
Date: Fri Sep  7 09:58:57 2018
New Revision: 341678

URL: http://llvm.org/viewvc/llvm-project?rev=341678&view=rev
Log:
[X86] Modify addcarry/subborrow builtins to emit an 2 result and intrinsic and an store instruction.

This is the clang side of D51769. The llvm intrinsics now return two results instead of using an out parameter.

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

Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/adc-builtins.c
    cfe/trunk/test/CodeGen/adx-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=341678&r1=341677&r2=341678&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Sep  7 09:58:57 2018
@@ -10405,6 +10405,41 @@ Value *CodeGenFunction::EmitX86BuiltinEx
                                       Ops[0]);
     return Builder.CreateExtractValue(Call, 1);
   }
+  case X86::BI__builtin_ia32_addcarryx_u32:
+  case X86::BI__builtin_ia32_addcarryx_u64:
+  case X86::BI__builtin_ia32_addcarry_u32:
+  case X86::BI__builtin_ia32_addcarry_u64:
+  case X86::BI__builtin_ia32_subborrow_u32:
+  case X86::BI__builtin_ia32_subborrow_u64: {
+    Intrinsic::ID IID;
+    switch (BuiltinID) {
+    default: llvm_unreachable("Unsupported intrinsic!");
+    case X86::BI__builtin_ia32_addcarryx_u32:
+      IID = Intrinsic::x86_addcarryx_u32;
+      break;
+    case X86::BI__builtin_ia32_addcarryx_u64:
+      IID = Intrinsic::x86_addcarryx_u64;
+      break;
+    case X86::BI__builtin_ia32_addcarry_u32:
+      IID = Intrinsic::x86_addcarry_u32;
+      break;
+    case X86::BI__builtin_ia32_addcarry_u64:
+      IID = Intrinsic::x86_addcarry_u64;
+      break;
+    case X86::BI__builtin_ia32_subborrow_u32:
+      IID = Intrinsic::x86_subborrow_u32;
+      break;
+    case X86::BI__builtin_ia32_subborrow_u64:
+      IID = Intrinsic::x86_subborrow_u64;
+      break;
+    }
+
+    Value *Call = Builder.CreateCall(CGM.getIntrinsic(IID),
+                                     { Ops[0], Ops[1], Ops[2] });
+    Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 1),
+                                      Ops[3]);
+    return Builder.CreateExtractValue(Call, 0);
+  }
 
   case X86::BI__builtin_ia32_fpclassps128_mask:
   case X86::BI__builtin_ia32_fpclassps256_mask:

Modified: cfe/trunk/test/CodeGen/adc-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/adc-builtins.c?rev=341678&r1=341677&r2=341678&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/adc-builtins.c (original)
+++ cfe/trunk/test/CodeGen/adc-builtins.c Fri Sep  7 09:58:57 2018
@@ -5,7 +5,10 @@
 unsigned char test_addcarry_u32(unsigned char __cf, unsigned int __x,
                                 unsigned int __y, unsigned int *__p) {
 // CHECK-LABEL: test_addcarry_u32
-// CHECK: call i8 @llvm.x86.addcarry.u32
+// CHECK: [[ADC:%.*]] = call { i8, i32 } @llvm.x86.addcarry.u32
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i32 } [[ADC]], 1
+// CHECK: store i32 [[DATA]], i32* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i32 } [[ADC]], 0
   return _addcarry_u32(__cf, __x, __y, __p);
 }
 
@@ -13,14 +16,20 @@ unsigned char test_addcarry_u64(unsigned
                                 unsigned long long __y,
                                 unsigned long long *__p) {
 // CHECK-LABEL: test_addcarry_u64
-// CHECK: call i8 @llvm.x86.addcarry.u64
+// CHECK: [[ADC:%.*]] = call { i8, i64 } @llvm.x86.addcarry.u64
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i64 } [[ADC]], 1
+// CHECK: store i64 [[DATA]], i64* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i64 } [[ADC]], 0
   return _addcarry_u64(__cf, __x, __y, __p);
 }
 
 unsigned char test_subborrow_u32(unsigned char __cf, unsigned int __x,
                                  unsigned int __y, unsigned int *__p) {
 // CHECK-LABEL: test_subborrow_u32
-// CHECK: call i8 @llvm.x86.subborrow.u32
+// CHECK: [[SBB:%.*]] = call { i8, i32 } @llvm.x86.subborrow.u32
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i32 } [[SBB]], 1
+// CHECK: store i32 [[DATA]], i32* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i32 } [[SBB]], 0
   return _subborrow_u32(__cf, __x, __y, __p);
 }
 
@@ -28,6 +37,9 @@ unsigned char test_subborrow_u64(unsigne
                                  unsigned long long __y,
                                  unsigned long long *__p) {
 // CHECK-LABEL: test_subborrow_u64
-// CHECK: call i8 @llvm.x86.subborrow.u64
+// CHECK: [[SBB:%.*]] = call { i8, i64 } @llvm.x86.subborrow.u64
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i64 } [[SBB]], 1
+// CHECK: store i64 [[DATA]], i64* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i64 } [[SBB]], 0
   return _subborrow_u64(__cf, __x, __y, __p);
 }

Modified: cfe/trunk/test/CodeGen/adx-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/adx-builtins.c?rev=341678&r1=341677&r2=341678&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/adx-builtins.c (original)
+++ cfe/trunk/test/CodeGen/adx-builtins.c Fri Sep  7 09:58:57 2018
@@ -5,7 +5,10 @@
 unsigned char test_addcarryx_u32(unsigned char __cf, unsigned int __x,
                                  unsigned int __y, unsigned int *__p) {
 // CHECK-LABEL: test_addcarryx_u32
-// CHECK: call i8 @llvm.x86.addcarryx.u32
+// CHECK: [[ADC:%.*]] = call { i8, i32 } @llvm.x86.addcarryx.u32
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i32 } [[ADC]], 1
+// CHECK: store i32 [[DATA]], i32* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i32 } [[ADC]], 0
   return _addcarryx_u32(__cf, __x, __y, __p);
 }
 
@@ -13,6 +16,9 @@ unsigned char test_addcarryx_u64(unsigne
                                  unsigned long long __y,
                                  unsigned long long *__p) {
 // CHECK-LABEL: test_addcarryx_u64
-// CHECK: call i8 @llvm.x86.addcarryx.u64
+// CHECK: [[ADC:%.*]] = call { i8, i64 } @llvm.x86.addcarryx.u64
+// CHECK: [[DATA:%.*]] = extractvalue { i8, i64 } [[ADC]], 1
+// CHECK: store i64 [[DATA]], i64* %{{.*}}
+// CHECK: [[CF:%.*]] = extractvalue { i8, i64 } [[ADC]], 0
   return _addcarryx_u64(__cf, __x, __y, __p);
 }




More information about the cfe-commits mailing list