-
Couldn't load subscription status.
- Fork 15k
[LoongArch] Fix MergeBaseOffset for constant pool index operand #159336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-backend-loongarch Author: hev (heiher) ChangesFixes #159200 Full diff: https://github.com/llvm/llvm-project/pull/159336.diff 5 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MachineOperand.h b/llvm/include/llvm/CodeGen/MachineOperand.h
index 646588a2a92a5..9104e93ed9783 100644
--- a/llvm/include/llvm/CodeGen/MachineOperand.h
+++ b/llvm/include/llvm/CodeGen/MachineOperand.h
@@ -788,6 +788,9 @@ class MachineOperand {
LLVM_ABI void ChangeToBA(const BlockAddress *BA, int64_t Offset,
unsigned TargetFlags = 0);
+ /// ChangeToCPI - Replace this operand with a new constant pool index operand.
+ LLVM_ABI void ChangeToCPI(unsigned Idx, int Offset, unsigned TargetFlags = 0);
+
/// ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
LLVM_ABI void ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags = 0);
diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index c612f8de7b50b..bb9c76ff0c729 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -218,6 +218,19 @@ void MachineOperand::ChangeToBA(const BlockAddress *BA, int64_t Offset,
setTargetFlags(TargetFlags);
}
+void MachineOperand::ChangeToCPI(unsigned Idx, int Offset,
+ unsigned TargetFlags) {
+ assert((!isReg() || !isTied()) &&
+ "Cannot change a tied operand into a constant pool index");
+
+ removeRegFromUses();
+
+ OpKind = MO_ConstantPoolIndex;
+ setIndex(Idx);
+ setOffset(Offset);
+ setTargetFlags(TargetFlags);
+}
+
void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags) {
assert((!isReg() || !isTied()) &&
"Cannot change a tied operand into an MCSymbol");
diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index b757d123fa0ff..2ab2a98c9434c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -162,7 +162,7 @@ bool LoongArchAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
else if (OffsetMO.isImm())
OS << ", " << OffsetMO.getImm();
else if (OffsetMO.isGlobal() || OffsetMO.isBlockAddress() ||
- OffsetMO.isMCSymbol()) {
+ OffsetMO.isMCSymbol() || OffsetMO.isCPI()) {
OS << ", ";
MAI->printExpr(OS, *MCO.getExpr());
} else
diff --git a/llvm/lib/Target/LoongArch/LoongArchMergeBaseOffset.cpp b/llvm/lib/Target/LoongArch/LoongArchMergeBaseOffset.cpp
index f62753356a4dd..a2292d016efa1 100644
--- a/llvm/lib/Target/LoongArch/LoongArchMergeBaseOffset.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchMergeBaseOffset.cpp
@@ -759,6 +759,10 @@ bool LoongArchMergeBaseOffsetOpt::foldIntoMemoryOps(MachineInstr &Hi20,
MO.ChangeToBA(ImmOp.getBlockAddress(), ImmOp.getOffset(),
LoongArchII::getDirectFlags(ImmOp));
break;
+ case MachineOperand::MO_ConstantPoolIndex:
+ MO.ChangeToCPI(ImmOp.getIndex(), ImmOp.getOffset(),
+ LoongArchII::getDirectFlags(ImmOp));
+ break;
default:
report_fatal_error("unsupported machine operand type");
break;
diff --git a/llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll b/llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
index 565ccdbe6880f..38e06d15670a8 100644
--- a/llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
+++ b/llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
@@ -142,6 +142,44 @@ define i32 @m_offset_2048(ptr %p) nounwind {
ret i32 %2
}
+define i32 @m_constant_0() nounwind {
+; LA32-LABEL: m_constant_0:
+; LA32: # %bb.0:
+; LA32-NEXT: pcalau12i $a0, %pc_hi20(.LCPI7_0)
+; LA32-NEXT: #APP
+; LA32-NEXT: #NO_APP
+; LA32-NEXT: ret
+;
+; LA64-LABEL: m_constant_0:
+; LA64: # %bb.0:
+; LA64-NEXT: pcalau12i $a0, %pc_hi20(.LCPI7_0)
+; LA64-NEXT: #APP
+; LA64-NEXT: #NO_APP
+; LA64-NEXT: ret
+ %1 = call i32 asm sideeffect "", "=r,m"(i64 0)
+ ret i32 %1
+}
+
+define i32 @m_constant_1() nounwind {
+; LA32-LABEL: m_constant_1:
+; LA32: # %bb.0:
+; LA32-NEXT: pcalau12i $a0, %pc_hi20(.LCPI8_0)
+; LA32-NEXT: #APP
+; LA32-NEXT: ld.w $a0, $a0, %pc_lo12(.LCPI8_0)
+; LA32-NEXT: #NO_APP
+; LA32-NEXT: ret
+;
+; LA64-LABEL: m_constant_1:
+; LA64: # %bb.0:
+; LA64-NEXT: pcalau12i $a0, %pc_hi20(.LCPI8_0)
+; LA64-NEXT: #APP
+; LA64-NEXT: ld.w $a0, $a0, %pc_lo12(.LCPI8_0)
+; LA64-NEXT: #NO_APP
+; LA64-NEXT: ret
+ %1 = call i32 asm sideeffect "ld.w $0, $1", "=r,m"(i64 1)
+ ret i32 %1
+}
+
@g_i32 = dso_local global i32 0
define i32 @m_addr_pcrel() nounwind {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. And is it necessary to cherry-pick to release/21.x?
Thanks. It should be cherry-picked to release/21.x. |
…#159336) Fixes llvm#159200 (cherry picked from commit 7ca448e)
Fixes #159200