[llvm] [M68k] Fix incorrect boolean content type (PR #152572)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 7 11:56:00 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-m68k

Author: Dan Salvato (dansalvato)

<details>
<summary>Changes</summary>

M68k's SETCC instruction (`scc`) distinctly fills the destination byte with all 1s. If boolean contents are set to `ZeroOrOneBooleanContent`, LLVM can mistakenly think the destination holds `0x01` instead of `0xff` and emit broken code as a result. This change corrects the boolean content type to `ZeroOrNegativeOneBooleanContent`.

For example, this IR:

```llvm
define dso_local signext range(i8 0, 2) i8 @<!-- -->testBool(i32 noundef %a) local_unnamed_addr #<!-- -->0 {
entry:
  %cmp = icmp eq i32 %a, 4660
  %. = zext i1 %cmp to i8
  ret i8 %.
}
```

would previously build as:

```asm
testBool:                               ; @<!-- -->testBool
	cmpi.l	#<!-- -->4660, (4,%sp)
	seq	%d0
	and.l	#<!-- -->255, %d0
	rts
```

Notice the `zext` is erroneously not clearing the low bits, and thus the register returns with 255 instead of 1. This patch fixes the issue:

```asm
testBool:                               ; @<!-- -->testBool
	cmpi.l	#<!-- -->4660, (4,%sp)
	seq	%d0
	and.l	#<!-- -->1, %d0
	rts
```

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


1 Files Affected:

- (modified) llvm/lib/Target/M68k/M68kISelLowering.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/Target/M68k/M68kISelLowering.cpp b/llvm/lib/Target/M68k/M68kISelLowering.cpp
index 594ea9f48c201..c6a20e211df7d 100644
--- a/llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ b/llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -51,7 +51,7 @@ M68kTargetLowering::M68kTargetLowering(const M68kTargetMachine &TM,
 
   MVT PtrVT = MVT::i32;
 
-  setBooleanContents(ZeroOrOneBooleanContent);
+  setBooleanContents(ZeroOrNegativeOneBooleanContent);
 
   auto *RegInfo = Subtarget.getRegisterInfo();
   setStackPointerRegisterToSaveRestore(RegInfo->getStackRegister());

``````````

</details>


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


More information about the llvm-commits mailing list