[llvm] 7f018b4 - [RISCV] Support SB/SH/SW in hasAllWUsers in RISCVSExtWRemoval.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 11:32:53 PST 2022


Author: Craig Topper
Date: 2022-11-09T11:32:19-08:00
New Revision: 7f018b45f937afcdff2acaa5cfa05825ddbeb1b7

URL: https://github.com/llvm/llvm-project/commit/7f018b45f937afcdff2acaa5cfa05825ddbeb1b7
DIFF: https://github.com/llvm/llvm-project/commit/7f018b45f937afcdff2acaa5cfa05825ddbeb1b7.diff

LOG: [RISCV] Support SB/SH/SW in hasAllWUsers in RISCVSExtWRemoval.

After D137446 we can see which operand is the user. If the user
is the value operand of a SB/SH/SW then the upper 32 bits aren't
used.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D137448

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
    llvm/test/CodeGen/RISCV/sextw-removal.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp b/llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
index d8791e86bd1fa..f7c0f123819d7 100644
--- a/llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
+++ b/llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
@@ -80,6 +80,7 @@ static bool hasAllWUsers(const MachineInstr &OrigMI, MachineRegisterInfo &MRI) {
 
     for (auto &UserOp : MRI.use_operands(MI->getOperand(0).getReg())) {
       const MachineInstr *UserMI = UserOp.getParent();
+      unsigned OpIdx = UserMI->getOperandNo(&UserOp);
 
       switch (UserMI->getOpcode()) {
       default:
@@ -142,6 +143,14 @@ static bool hasAllWUsers(const MachineInstr &OrigMI, MachineRegisterInfo &MRI) {
           return false;
         break;
 
+      case RISCV::SB:
+      case RISCV::SH:
+      case RISCV::SW:
+        // The first argument is the value to store.
+        if (OpIdx != 0)
+          return false;
+        break;
+
       // For these, lower word of output in these operations, depends only on
       // the lower word of input. So, we check all uses only read lower word.
       case RISCV::COPY:

diff  --git a/llvm/test/CodeGen/RISCV/sextw-removal.ll b/llvm/test/CodeGen/RISCV/sextw-removal.ll
index fa1a3b493e169..b3abb7dd12160 100644
--- a/llvm/test/CodeGen/RISCV/sextw-removal.ll
+++ b/llvm/test/CodeGen/RISCV/sextw-removal.ll
@@ -971,3 +971,51 @@ define signext i32 @test14d(i31 zeroext %0, i32 signext %1) {
   %13 = phi i32 [ %zext, %2 ], [ -1, %4 ], [ %9, %8 ]
   ret i32 %13
 }
+
+define signext i32 @test15(i64 %arg1, i64 %arg2, i64 %arg3, i32* %arg4)  {
+; CHECK-LABEL: test15:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    addi a2, a2, -1
+; CHECK-NEXT:    li a4, 256
+; CHECK-NEXT:  .LBB17_1: # %bb2
+; CHECK-NEXT:    # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:    andi a0, a0, 1234
+; CHECK-NEXT:    addw a0, a0, a1
+; CHECK-NEXT:    addi a2, a2, 1
+; CHECK-NEXT:    sw a0, 0(a3)
+; CHECK-NEXT:    bltu a2, a4, .LBB17_1
+; CHECK-NEXT:  # %bb.2: # %bb7
+; CHECK-NEXT:    ret
+;
+; NOREMOVAL-LABEL: test15:
+; NOREMOVAL:       # %bb.0: # %entry
+; NOREMOVAL-NEXT:    addi a2, a2, -1
+; NOREMOVAL-NEXT:    li a4, 256
+; NOREMOVAL-NEXT:  .LBB17_1: # %bb2
+; NOREMOVAL-NEXT:    # =>This Inner Loop Header: Depth=1
+; NOREMOVAL-NEXT:    andi a0, a0, 1234
+; NOREMOVAL-NEXT:    add a0, a0, a1
+; NOREMOVAL-NEXT:    addi a2, a2, 1
+; NOREMOVAL-NEXT:    sw a0, 0(a3)
+; NOREMOVAL-NEXT:    bltu a2, a4, .LBB17_1
+; NOREMOVAL-NEXT:  # %bb.2: # %bb7
+; NOREMOVAL-NEXT:    sext.w a0, a0
+; NOREMOVAL-NEXT:    ret
+entry:
+  br label %bb2
+
+bb2:                                              ; preds = %bb2, %entry
+  %i1 = phi i64 [ %arg1, %entry ], [ %i5, %bb2 ]
+  %i2 = phi i64 [ %arg3, %entry ], [ %i3, %bb2 ]
+  %i3 = add i64 %i2, 1
+  %i4 = and i64 %i1, 1234
+  %i5 = add i64 %i4, %arg2
+  %i8 = trunc i64 %i5 to i32
+  store i32 %i8, i32* %arg4
+  %i6 = icmp ugt i64 %i2, 255
+  br i1 %i6, label %bb7, label %bb2
+
+bb7:                                              ; preds = %bb2
+  %i7 = trunc i64 %i5 to i32
+  ret i32 %i7
+}


        


More information about the llvm-commits mailing list