gemini-code-assist[bot] commented on code in PR #599:
URL: https://github.com/apache/tvm-ffi/pull/599#discussion_r3318918050


##########
include/tvm/ffi/base_details.h:
##########
@@ -114,6 +114,30 @@
 #define TVM_FFI_PREDICT_TRUE(cond) (cond)
 #endif
 
+/*!
+ * \brief Translates into __builtin_assume / __assume / 
__attribute__((assume)).
+ *
+ * Use ONLY when the external invariant guarantees cond. The compiler
+ * will remove all paths inconsistent with cond. This is not an
+ * assertion or check -- using on a wrong cond will result in
+ * undefined behavior. cond must be side-effect-free.
+ */
+#if defined(__clang__)
+#define TVM_FFI_UNSAFE_ASSUME(cond) __builtin_assume(cond)
+#elif defined(__GNUC__)
+/* GCC 13+ supports __attribute__((assume(...))); fall back to the void-cast
+ * no-op for older GCC where __builtin_assume is absent. */
+#if __GNUC__ >= 13
+#define TVM_FFI_UNSAFE_ASSUME(cond) __attribute__((assume(cond)))
+#else
+#define TVM_FFI_UNSAFE_ASSUME(cond) static_cast<void>(0)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For GCC versions older than 13, `static_cast<void>(0)` completely discards 
the assumption, losing valuable optimization opportunities. We can instead use 
`__builtin_unreachable()` to convey the assumption to the compiler, which is 
highly effective and widely supported in older GCC versions.
   
   ```c
   #define TVM_FFI_UNSAFE_ASSUME(cond) ((cond) ? static_cast<void>(0) : 
__builtin_unreachable())
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to