-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[C API] Add getter/setter for samesign flag on icmp #145247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This was added to the C++ API in llvm#111419 so this change adds accessors in the C API, along with a couple tests.
@llvm/pr-subscribers-llvm-ir Author: Benji Smith (Benjins) ChangesThis was added to the C++ API in #111419 so this change adds accessors in the C API, along with a couple tests. Full diff: https://github.com/llvm/llvm-project/pull/145247.diff 5 Files Affected:
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 0395f43c61953..95bcc1a1f3f55 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -251,6 +251,9 @@ Changes to the C API
* Added ``LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision`` for creating
debugging metadata of enumerators larger than 64 bits.
+* Added ``LLVMGetICmpSameSign`` and ``LLVMSetICmpSameSign`` for the `samesign`
+ flag on `icmp` instructions.
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 6857944e6875f..3f30ed92997b4 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3675,6 +3675,24 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
*/
LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
+/**
+ * Get whether or not an icmp instruction has the samesign flag.
+ *
+ * This is only valid for instructions that correspond to llvm::ICmpInst.
+ *
+ * @see llvm::ICmpInst::hasSameSign()
+ */
+LLVMBool LLVMGetICmpSameSign(LLVMValueRef Inst);
+
+/**
+ * Set the samesign flag on an icmp instruction.
+ *
+ * This is only valid for instructions that correspond to llvm::ICmpInst.
+ *
+ * @see llvm::ICmpInst::setSameSign()
+ */
+void LLVMSetICmpSameSign(LLVMValueRef Inst, LLVMBool SameSign);
+
/**
* Obtain the float predicate of an instruction.
*
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 9810f04cc503c..f7ef4aa473ef5 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -2951,6 +2951,14 @@ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
return (LLVMIntPredicate)0;
}
+LLVMBool LLVMGetICmpSameSign(LLVMValueRef Inst) {
+ return unwrap<ICmpInst>(Inst)->hasSameSign();
+}
+
+void LLVMSetICmpSameSign(LLVMValueRef Inst, LLVMBool SameSign) {
+ unwrap<ICmpInst>(Inst)->setSameSign(SameSign);
+}
+
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst) {
if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
return (LLVMRealPredicate)I->getPredicate();
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index 0a688afab6125..ab1771d1f879f 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -417,6 +417,14 @@ define ptr @test_gep_no_wrap_flags(ptr %0) {
ret ptr %gep.nusw
}
+define void @test_icmp_same_sign(i32 %a, i32 %b) {
+ %icmp.1 = icmp eq i32 %a, %b
+ %icmp.2 = icmp slt i32 %a, %b
+ %icmp.3 = icmp samesign eq i32 %a, %b
+ %icmp.4 = icmp samesign slt i32 %a, %b
+ ret void
+}
+
!llvm.dbg.cu = !{!0, !2}
!llvm.module.flags = !{!3}
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index 3ec40fdba0bad..026d815b43da7 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -823,9 +823,11 @@ struct FunCloner {
}
case LLVMICmp: {
LLVMIntPredicate Pred = LLVMGetICmpPredicate(Src);
+ LLVMBool IsSameSign = LLVMGetICmpSameSign(Src);
LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
Dst = LLVMBuildICmp(Builder, Pred, LHS, RHS, Name);
+ LLVMSetICmpSameSign(Dst, IsSameSign);
break;
}
case LLVMPHI: {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/13139 Here is the relevant piece of the build log for the reference
|
This was added to the C++ API in llvm#111419 so this change adds accessors in the C API, along with a couple tests.
This was added to the C++ API in llvm#111419 so this change adds accessors in the C API, along with a couple tests.
This was added to the C++ API in #111419 so this change adds accessors in the C API, along with a couple tests.