[PATCH] D25265: [C API] Add test for D25259 and new LLVMIsExact function.

Amaury SECHET via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 15:38:02 PST 2017


deadalnix updated this revision to Diff 85646.
deadalnix added a comment.

Pinging this. I think this is fine and should proceed.


https://reviews.llvm.org/D25265

Files:
  include/llvm-c/Core.h
  lib/IR/Core.cpp
  test/Bindings/llvm-c/echo.ll
  tools/llvm-c-test/echo.cpp


Index: tools/llvm-c-test/echo.cpp
===================================================================
--- tools/llvm-c-test/echo.cpp
+++ tools/llvm-c-test/echo.cpp
@@ -480,13 +480,19 @@
       case LLVMUDiv: {
         LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
         LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
-        Dst = LLVMBuildUDiv(Builder, LHS, RHS, Name);
+        if (LLVMIsExact(Src))
+            Dst = LLVMBuildExactUDiv(Builder, LHS, RHS, Name);
+        else
+            Dst = LLVMBuildUDiv(Builder, LHS, RHS, Name);
         break;
       }
       case LLVMSDiv: {
         LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
         LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
-        Dst = LLVMBuildSDiv(Builder, LHS, RHS, Name);
+        if (LLVMIsExact(Src))
+            Dst = LLVMBuildExactSDiv(Builder, LHS, RHS, Name);
+        else
+            Dst = LLVMBuildSDiv(Builder, LHS, RHS, Name);
         break;
       }
       case LLVMURem: {
Index: test/Bindings/llvm-c/echo.ll
===================================================================
--- test/Bindings/llvm-c/echo.ll
+++ test/Bindings/llvm-c/echo.ll
@@ -51,6 +51,8 @@
   %3 = sub i32 %2, %1
   %4 = udiv i32 %3, %b
   %5 = sdiv i32 %2, %4
+  %e4 = udiv exact i32 %3, %b
+  %e5 = sdiv exact i32 %2, %4
   %6 = urem i32 %3, %5
   %7 = srem i32 %2, %6
   %8 = shl i32 %1, %b
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -2669,6 +2669,10 @@
   return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
 }
 
+LLVMBool LLVMIsExact(LLVMValueRef V) {
+    return cast<PossiblyExactOperator>(unwrap(V))->isExact();
+}
+
 /*--.. Memory ..............................................................--*/
 
 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -2919,6 +2919,8 @@
 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
 
+LLVMBool LLVMIsExact(LLVMValueRef V);
+
 /* Memory */
 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25265.85646.patch
Type: text/x-patch
Size: 2405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170124/7d4c77f4/attachment.bin>


More information about the llvm-commits mailing list