Skip to content

[llvm-c] Add support for setting/getting new disjoint flag on or instructions #74517

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

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

asb
Copy link
Contributor

@asb asb commented Dec 5, 2023

Follows #73952 doing the same thing for the nneg flag on zext (i.e., exposing support in the C API).

…ructions

Follows llvm#73952 doing the same thing for the nneg flag on zext.
@asb asb requested review from nikic and topperc December 5, 2023 20:27
@llvmbot llvmbot added the llvm:ir label Dec 5, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-llvm-ir

Author: Alex Bradbury (asb)

Changes

Follows #73952 doing the same thing for the nneg flag on zext (i.e., exposing support in the C API).


Full diff: https://github.com/llvm/llvm-project/pull/74517.diff

5 Files Affected:

  • (modified) llvm/docs/ReleaseNotes.rst (+3-2)
  • (modified) llvm/include/llvm-c/Core.h (+11)
  • (modified) llvm/lib/IR/Core.cpp (+10)
  • (modified) llvm/test/Bindings/llvm-c/echo.ll (+2-1)
  • (modified) llvm/tools/llvm-c-test/echo.cpp (+2)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 0a80a25c79f86..f58ae03a6efcf 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -200,8 +200,9 @@ Changes to the C API
   The option structure exposes an additional setting (i.e., the target ABI) and
   provides default values for unspecified settings.
 
-* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for setting/getting the new nneg flag
-  on zext instructions
+* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for getting/setting the new nneg flag
+  on zext instructions, and ``LLVMGetIsDisjoint`` and ``LLVMSetIsDisjoint``
+  for getting/setting the new disjoint flag on or instructions.
 
 Changes to the CodeGen infrastructure
 -------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index b16f67ef02f33..7c49451d9aa6b 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3985,6 +3985,17 @@ LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst);
  */
 void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg);
 
+/**
+ * Gets if the instruction has the disjoint flag set
+ * Only valid for or instructions
+ */
+LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst);
+/**
+ * Sets the disjoint flag for the instruction
+ * Only valid for or instructions
+ */
+void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint);
+
 /* Memory */
 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index e07664f8a17c6..7832028bf3671 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3464,6 +3464,16 @@ void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg) {
   cast<Instruction>(P)->setNonNeg(IsNonNeg);
 }
 
+LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst) {
+  Value *P = unwrap<Value>(Inst);
+  return cast<PossiblyDisjointInst>(P)->isDisjoint();
+}
+
+void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint) {
+  Value *P = unwrap<Value>(Inst);
+  cast<PossiblyDisjointInst>(P)->setIsDisjoint(IsDisjoint);
+}
+
 /*--.. Memory ..............................................................--*/
 
 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index 72d5b455badcb..0775cbb673e4e 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -92,7 +92,8 @@ define i32 @iops(i32 %a, i32 %b) {
   %23 = ashr exact i32 %22, %14
   %24 = zext i32 %23 to i64
   %25 = zext nneg i32 %23 to i64
-  ret i32 %23
+  %26 = or disjoint i32 %23, %a
+  ret i32 %26
 }
 
 define i32 @call() {
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index 3b07ccb29f3e0..e2617583ff9ba 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -656,7 +656,9 @@ struct FunCloner {
       case LLVMOr: {
         LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
         LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
+        LLVMBool IsDisjoint = LLVMGetIsDisjoint(Src);
         Dst = LLVMBuildOr(Builder, LHS, RHS, Name);
+        LLVMSetIsDisjoint(Dst, IsDisjoint);
         break;
       }
       case LLVMXor: {

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asb asb merged commit 46a36af into llvm:main Dec 6, 2023
asb added a commit that referenced this pull request Dec 6, 2023
I'd copied and adjusted the doc comments for LLVMGetNNeg and LLVMSetNNeg
in #74517. Nikita pointed out in that review my comments were missing a
full stop, so I'm applying the same fix to these.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants