[clang] [compiler-rt] [llvm] [TargetLowering] Set the default `getCmpLibcallReturnType` to word size (PR #192441)

Trevor Gross via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 26 14:44:15 PDT 2026


================
@@ -996,8 +996,13 @@ class LLVM_ABI TargetLoweringBase {
   /// Return the ValueType for comparison libcalls. Comparison libcalls include
   /// floating point comparison calls, and Ordered/Unordered check calls on
   /// floating point numbers.
-  virtual MVT::SimpleValueType getCmpLibcallReturnType() const {
-    return MVT::i32; // return the default value
+  ///
+  /// This should match `CMP_RESULT` in `compiler-rt` and `CMPtype` in
+  /// `libgcc`. The default return is word-sized. Consider overriding on
+  /// targets that have a cheaper comparison at other sizes.
+  virtual MVT::SimpleValueType
+  getCmpLibcallReturnType(const DataLayout &DL) const {
+    return getPointerTy(DL).SimpleTy;
----------------
tgross35 wrote:

I dug a bit and found that in Clang, `__attribute__ ((mode (word)))` comes from `getRegisterWidth` https://github.com/llvm/llvm-project/blob/544d003630475c65f6d85d1edb4467e9d7a16c0f/clang/include/clang/Basic/TargetInfo.h#L906-L912. To be consistent, I added a `getRegisterWidth` to the LLVM side and called that from `getCmpLibcallReturnType`. Happy to change back if you prefer it inlined still though, since it is only used in the one place.

Is there a way for Clang's `TargetInfo` to make use of LLVM's `DataLayout`? I think the best case scenario is for `getRegisterWidth` to live in LLVM and Clang could just call that, but I'm not sure how.

https://github.com/llvm/llvm-project/pull/192441


More information about the cfe-commits mailing list