diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td @@ -93,7 +93,7 @@ //===----------------------------------------------------------------------===// let Predicates = [HasStdExtZfa] in { -let isAsCheapAsAMove = 1 in +let isReMaterializable = 1, isAsCheapAsAMove = 1 in def FLI_S : FPUnaryOp_imm<0b1111000, 0b00001, 0b000, OPC_OP_FP, (outs FPR32:$rd), (ins loadfp32imm:$imm), "fli.s", "$rd, $imm">; @@ -108,7 +108,7 @@ } // Predicates = [HasStdExtZfa] let Predicates = [HasStdExtZfa, HasStdExtD] in { -let isAsCheapAsAMove = 1 in +let isReMaterializable = 1, isAsCheapAsAMove = 1 in def FLI_D : FPUnaryOp_imm<0b1111001, 0b00001, 0b000, OPC_OP_FP, (outs FPR64:$rd), (ins loadfp64imm:$imm), "fli.d", "$rd, $imm">; @@ -138,7 +138,7 @@ } // Predicates = [HasStdExtZfa, HasStdExtD, IsRV32] let Predicates = [HasStdExtZfa, HasStdExtZfhOrZvfh] in -let isAsCheapAsAMove = 1 in +let isReMaterializable = 1, isAsCheapAsAMove = 1 in def FLI_H : FPUnaryOp_imm<0b1111010, 0b00001, 0b000, OPC_OP_FP, (outs FPR16:$rd), (ins loadfp16imm:$imm), "fli.h", "$rd, $imm">; diff --git a/llvm/test/CodeGen/RISCV/float-zfa.ll b/llvm/test/CodeGen/RISCV/float-zfa.ll --- a/llvm/test/CodeGen/RISCV/float-zfa.ll +++ b/llvm/test/CodeGen/RISCV/float-zfa.ll @@ -227,3 +227,16 @@ %2 = zext i1 %1 to i32 ret i32 %2 } + +declare void @foo(float, float) + +; Make sure we use two fli instructions instead of copying. +define void @fli_remat() { +; CHECK-LABEL: fli_remat: +; CHECK: # %bb.0: +; CHECK-NEXT: fli.s fa0, 1.0 +; CHECK-NEXT: fli.s fa1, 1.0 +; CHECK-NEXT: tail foo@plt + tail call void @foo(float 1.000000e+00, float 1.000000e+00) + ret void +}