[llvm] [ARM] Add a method to clear registers (PR #69659)

Bill Wendling via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 15:46:38 PDT 2023


================
@@ -6735,6 +6735,15 @@ MachineBasicBlock::iterator ARMBaseInstrInfo::insertOutlinedCall(
   return CallPt;
 }
 
+void ARMBaseInstrInfo::buildClearRegister(Register DstReg,
+                                          MachineBasicBlock &MBB,
+                                          MachineBasicBlock::iterator Iter,
+                                          DebugLoc &DL,
+                                          bool AllowSideEffects) const {
+  unsigned Opc = Subtarget.isThumb2() ? ARM::t2MOVi32imm : ARM::MOVi32imm;
----------------
bwendling wrote:

Avoiding side effects should always be desirable / safe. The only reason to allow them is if an alternative instruction (e.g. `xor` on x86) is smaller or more efficient or whatever. In the case of ARM / AArch64, the size of the instruction doesn't matter of course. However, ARM does produce code like this when exiting the function with stack protectors:

```
	cmp	r1, r0
	addeq	sp, sp, #8
	addeq	sp, sp, #1024
	popeq	{r11, pc}
```

So shoving a side-effect after the `cmp` instruction won't be good. Yes, I will have `AllowSideEffects == false` in that case, but I don't see why we would allow side-effects at all unless it's clearly a win.

After looking at the documentation, it *does* appear that the Thumb1 version of `MOV Rn, #imm` won't modify the condition flags, unless we specify it to. I'll make that change.

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


More information about the llvm-commits mailing list