public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114673] New: RISC-V: "L" constraint cannot be used for lui in inline asm
@ 2024-04-10 6:16 cmuellner at gcc dot gnu.org
2024-04-10 7:46 ` [Bug target/114673] " schwab@linux-m68k.org
0 siblings, 1 reply; 2+ messages in thread
From: cmuellner at gcc dot gnu.org @ 2024-04-10 6:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114673
Bug ID: 114673
Summary: RISC-V: "L" constraint cannot be used for lui in
inline asm
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: cmuellner at gcc dot gnu.org
Target Milestone: ---
The RISC-V-specific "L" constraint is neither documented nor tested.
In constraints.md it is defined as "A U-type 20-bit signed immediate.".
It tests if the value is a constant int that satisfies LUI_OPERAND(),
i.e. a value with the lowest 12 bits zero.
One obvious use-case is to use "L" for "lui" in inline asm.
However, it does not work as expected:
long getB()
{
//lui a0,0x1800
return 3<<23; //0x01800000
}
long getB_asm_i()
{
long reg;
//lui a0,0x1800
asm("lui %0, %1" : "=r"(reg) : "i"((3<<23) >> 12));
return reg;
}
long getB_asm_L()
{
long reg;
//Assembler error: lui expression not in range 0..1048575
asm("lui %0, %1" : "=r"(reg) : "L"(3ul<<23));
return reg;
}
long getB_asm_Lshift()
{
long reg;
//Compiler error: impossible constraint in 'asm'
asm("lui %0, %1" : "=r"(reg) : "L"((3<<23) >> 12));
return reg;
}
The "L" constraint was introduced as part of the initial RISC-V port.
I could not find any tests/documentation, so I am unsure if it can be fixed
or if a new constraint should be introduced.
My preferred fix would be to shift the provided constant right by 12
if it satisfies LUI_OPERAND(), so that getB_asm_L() would work.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug target/114673] RISC-V: "L" constraint cannot be used for lui in inline asm
2024-04-10 6:16 [Bug target/114673] New: RISC-V: "L" constraint cannot be used for lui in inline asm cmuellner at gcc dot gnu.org
@ 2024-04-10 7:46 ` schwab@linux-m68k.org
0 siblings, 0 replies; 2+ messages in thread
From: schwab@linux-m68k.org @ 2024-04-10 7:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114673
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
There is a single use in md files:
(define_insn "*mov<GPR:mode><X:mode>cc"
[(set (match_operand:GPR 0 "register_operand" "=r,r")
(if_then_else:GPR
(match_operator 5 "ordered_comparison_operator"
[(match_operand:X 1 "register_operand" "r,r")
(match_operand:X 2 "reg_or_0_operand" "rJ,rJ")])
(match_operand:GPR 3 "register_operand" "0,0")
(match_operand:GPR 4 "sfb_alu_operand" "rJ,IL")))]
"TARGET_SFB_ALU"
"@
b%C5\t%1,%z2,1f\t# movcc\;mv\t%0,%z4\n1:
b%C5\t%1,%z2,1f\t# movcc\;li\t%0,%4\n1:"
[(set_attr "length" "8")
(set_attr "type" "sfb_alu")
(set_attr "mode" "<GPR:MODE>")])
Here the operand is used with li, but the assembler can emit it as lui.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-10 7:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10 6:16 [Bug target/114673] New: RISC-V: "L" constraint cannot be used for lui in inline asm cmuellner at gcc dot gnu.org
2024-04-10 7:46 ` [Bug target/114673] " schwab@linux-m68k.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).