[llvm] [BPF] Remove 'may_goto 0' instructions (PR #123482)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 22:50:40 PST 2025
================
@@ -682,6 +685,56 @@ bool BPFMIPreEmitPeephole::insertMissingCallerSavedSpills() {
return Changed;
}
+bool BPFMIPreEmitPeephole::removeMayGotoZero() {
+ bool Changed = false;
+ MachineBasicBlock *Prev_MBB, *Curr_MBB = nullptr;
+
+ for (MachineBasicBlock &MBB : make_early_inc_range(reverse(*MF))) {
+ Prev_MBB = Curr_MBB;
+ Curr_MBB = &MBB;
+ if (Prev_MBB == nullptr)
+ continue;
+
+ MachineInstr &MI = MBB.back();
+ if (MI.getOpcode() != TargetOpcode::INLINEASM_BR)
+ continue;
+
+ const char *AsmStr = MI.getOperand(0).getSymbolName();
+ SmallVector<StringRef, 4> AsmPieces;
+ SplitString(AsmStr, AsmPieces, ";\n");
----------------
yonghong-song wrote:
I used the approach similar to ARM/ARMISelLowering.cpp:
```
InlineAsm *IA = cast<InlineAsm>(CI->getCalledOperand());
StringRef AsmStr = IA->getAsmString();
SmallVector<StringRef, 4> AsmPieces;
SplitString(AsmStr, AsmPieces, ";\n");
switch (AsmPieces.size()) {
default: return false;
case 1:
AsmStr = AsmPieces[0];
AsmPieces.clear();
SplitString(AsmStr, AsmPieces, " \t,");
// rev $0, $1
if (AsmPieces.size() == 3 &&
AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" &&
IA->getConstraintString().compare(0, 4, "=l,l") == 0) {
IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
if (Ty && Ty->getBitWidth() == 32)
return IntrinsicLowering::LowerToByteSwap(CI);
}
break;
}
```
The code already enforced only one asm insn is allowed. see
```
// Do not support multiple insns in one inline asm.
if (AsmPieces.size() != 1)
continue;
```
Maybe I missed something here?
https://github.com/llvm/llvm-project/pull/123482
More information about the llvm-commits
mailing list