[RISCV] Use gorciw for i32 orc.b intrinsic when Zbp is enabled.
authorCraig Topper <craig.topper@sifive.com>
Sun, 4 Apr 2021 22:40:41 +0000 (15:40 -0700)
committerCraig Topper <craig.topper@sifive.com>
Mon, 5 Apr 2021 00:14:28 +0000 (17:14 -0700)
The W version of orc.b does not exist in Zbp so we need to use
gorci encoding. If we have Zbp, we can use gorciw which can avoid a
sext.w in some cases.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll

index 9388300..75ad5b9 100644 (file)
@@ -4211,7 +4211,10 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
       // Lower to the GORCI encoding for orc.b with the operand extended.
       SDValue NewOp =
           DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
-      SDValue Res = DAG.getNode(RISCVISD::GORCI, DL, MVT::i64, NewOp,
+      // If Zbp is enabled, use GORCIW which will sign extend the result.
+      unsigned Opc =
+          Subtarget.hasStdExtZbp() ? RISCVISD::GORCIW : RISCVISD::GORCI;
+      SDValue Res = DAG.getNode(Opc, DL, MVT::i64, NewOp,
                                 DAG.getTargetConstant(7, DL, MVT::i64));
       Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
       return;
index 262ed78..834a76e 100644 (file)
@@ -9,8 +9,7 @@ declare i32 @llvm.riscv.orc.b.i32(i32)
 define signext i32 @orcb32(i32 signext %a) nounwind {
 ; RV64IB-LABEL: orcb32:
 ; RV64IB:       # %bb.0:
-; RV64IB-NEXT:    orc.b a0, a0
-; RV64IB-NEXT:    sext.w a0, a0
+; RV64IB-NEXT:    gorciw a0, a0, 7
 ; RV64IB-NEXT:    ret
 ;
 ; RV64IBB-LABEL: orcb32: