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

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 02:55:04 PST 2023


https://github.com/asb updated https://github.com/llvm/llvm-project/pull/74517

>From 5e8ceba0f2c013ab6dd61fba3b23f0aeaddbf54b Mon Sep 17 00:00:00 2001
From: Alex Bradbury <asb at igalia.com>
Date: Tue, 5 Dec 2023 20:22:51 +0000
Subject: [PATCH 1/2] [llvm-c] Add support for setting/getting new disjoint
 flag on or instructions

Follows #73952 doing the same thing for the nneg flag on zext.
---
 llvm/docs/ReleaseNotes.rst        |  5 +++--
 llvm/include/llvm-c/Core.h        | 11 +++++++++++
 llvm/lib/IR/Core.cpp              | 10 ++++++++++
 llvm/test/Bindings/llvm-c/echo.ll |  3 ++-
 llvm/tools/llvm-c-test/echo.cpp   |  2 ++
 5 files changed, 28 insertions(+), 3 deletions(-)

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: {

>From d8b3485a82934cca9444c1628ced81f7a2596549 Mon Sep 17 00:00:00 2001
From: Alex Bradbury <asb at asbradbury.org>
Date: Wed, 6 Dec 2023 10:54:57 +0000
Subject: [PATCH 2/2] Apply suggestions from code review

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/include/llvm-c/Core.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 7c49451d9aa6b..163cfdcb8da20 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3986,13 +3986,13 @@ LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst);
 void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg);
 
 /**
- * Gets if the instruction has the disjoint flag set
- * Only valid for or instructions
+ * Gets whether 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
+ * Sets the disjoint flag for the instruction.
+ * Only valid for or instructions.
  */
 void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint);
 



More information about the llvm-commits mailing list