Skip to content

[NVPTX] tryStoreParam - remove default-only switch statement. NFC. #145948

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

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

RKSimon
Copy link
Collaborator

@RKSimon RKSimon commented Jun 26, 2025

#145581 removed all the remaining special cases from the switch statement leaving just the default, which MSVC complains about.

llvm#145581 remove all the remaining special cases from the switch statement leaving just the default, which MSVC complains about.
@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-backend-nvptx

Author: Simon Pilgrim (RKSimon)

Changes

#145581 remove all the remaining special cases from the switch statement leaving just the default, which MSVC complains about.


Full diff: https://github.com/llvm/llvm-project/pull/145948.diff

1 Files Affected:

  • (modified) llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp (+46-51)
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
index 5ee1bee49247c..7c1d13119fa18 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
@@ -1713,62 +1713,57 @@ bool NVPTXDAGToDAGISel::tryStoreParam(SDNode *N) {
   // If we have an i1, use an 8-bit store. The lowering code in
   // NVPTXISelLowering will have already emitted an upcast.
   std::optional<unsigned> Opcode;
-  switch (N->getOpcode()) {
+  switch (NumElts) {
   default:
-    switch (NumElts) {
-    default:
-      llvm_unreachable("Unexpected NumElts");
-    case 1: {
-      MVT::SimpleValueType MemTy = Mem->getMemoryVT().getSimpleVT().SimpleTy;
-      SDValue Imm = Ops[0];
-      if (MemTy != MVT::f16 && MemTy != MVT::bf16 &&
-          (isa<ConstantSDNode>(Imm) || isa<ConstantFPSDNode>(Imm))) {
-        // Convert immediate to target constant
-        if (MemTy == MVT::f32 || MemTy == MVT::f64) {
-          const ConstantFPSDNode *ConstImm = cast<ConstantFPSDNode>(Imm);
-          const ConstantFP *CF = ConstImm->getConstantFPValue();
-          Imm = CurDAG->getTargetConstantFP(*CF, DL, Imm->getValueType(0));
-        } else {
-          const ConstantSDNode *ConstImm = cast<ConstantSDNode>(Imm);
-          const ConstantInt *CI = ConstImm->getConstantIntValue();
-          Imm = CurDAG->getTargetConstant(*CI, DL, Imm->getValueType(0));
-        }
-        Ops[0] = Imm;
-        // Use immediate version of store param
-        Opcode = pickOpcodeForVT(MemTy, NVPTX::StoreParamI8_i,
-                                 NVPTX::StoreParamI16_i, NVPTX::StoreParamI32_i,
-                                 NVPTX::StoreParamI64_i);
-      } else
-        Opcode =
-            pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
-                            NVPTX::StoreParamI8_r, NVPTX::StoreParamI16_r,
-                            NVPTX::StoreParamI32_r, NVPTX::StoreParamI64_r);
-      if (Opcode == NVPTX::StoreParamI8_r) {
-        // Fine tune the opcode depending on the size of the operand.
-        // This helps to avoid creating redundant COPY instructions in
-        // InstrEmitter::AddRegisterOperand().
-        switch (Ops[0].getSimpleValueType().SimpleTy) {
-        default:
-          break;
-        case MVT::i32:
-          Opcode = NVPTX::StoreParamI8TruncI32_r;
-          break;
-        case MVT::i64:
-          Opcode = NVPTX::StoreParamI8TruncI64_r;
-          break;
-        }
+    llvm_unreachable("Unexpected NumElts");
+  case 1: {
+    MVT::SimpleValueType MemTy = Mem->getMemoryVT().getSimpleVT().SimpleTy;
+    SDValue Imm = Ops[0];
+    if (MemTy != MVT::f16 && MemTy != MVT::bf16 &&
+        (isa<ConstantSDNode>(Imm) || isa<ConstantFPSDNode>(Imm))) {
+      // Convert immediate to target constant
+      if (MemTy == MVT::f32 || MemTy == MVT::f64) {
+        const ConstantFPSDNode *ConstImm = cast<ConstantFPSDNode>(Imm);
+        const ConstantFP *CF = ConstImm->getConstantFPValue();
+        Imm = CurDAG->getTargetConstantFP(*CF, DL, Imm->getValueType(0));
+      } else {
+        const ConstantSDNode *ConstImm = cast<ConstantSDNode>(Imm);
+        const ConstantInt *CI = ConstImm->getConstantIntValue();
+        Imm = CurDAG->getTargetConstant(*CI, DL, Imm->getValueType(0));
+      }
+      Ops[0] = Imm;
+      // Use immediate version of store param
+      Opcode =
+          pickOpcodeForVT(MemTy, NVPTX::StoreParamI8_i, NVPTX::StoreParamI16_i,
+                          NVPTX::StoreParamI32_i, NVPTX::StoreParamI64_i);
+    } else
+      Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
+                               NVPTX::StoreParamI8_r, NVPTX::StoreParamI16_r,
+                               NVPTX::StoreParamI32_r, NVPTX::StoreParamI64_r);
+    if (Opcode == NVPTX::StoreParamI8_r) {
+      // Fine tune the opcode depending on the size of the operand.
+      // This helps to avoid creating redundant COPY instructions in
+      // InstrEmitter::AddRegisterOperand().
+      switch (Ops[0].getSimpleValueType().SimpleTy) {
+      default:
+        break;
+      case MVT::i32:
+        Opcode = NVPTX::StoreParamI8TruncI32_r;
+        break;
+      case MVT::i64:
+        Opcode = NVPTX::StoreParamI8TruncI64_r;
+        break;
       }
-      break;
-    }
-    case 2:
-    case 4: {
-      MVT::SimpleValueType MemTy = Mem->getMemoryVT().getSimpleVT().SimpleTy;
-      Opcode = pickOpcodeForVectorStParam(Ops, NumElts, MemTy, CurDAG, DL);
-      break;
-    }
     }
     break;
   }
+  case 2:
+  case 4: {
+    MVT::SimpleValueType MemTy = Mem->getMemoryVT().getSimpleVT().SimpleTy;
+    Opcode = pickOpcodeForVectorStParam(Ops, NumElts, MemTy, CurDAG, DL);
+    break;
+  }
+  }
 
   SDVTList RetVTs = CurDAG->getVTList(MVT::Other, MVT::Glue);
   SDNode *Ret = CurDAG->getMachineNode(*Opcode, DL, RetVTs, Ops);

Copy link
Member

@AlexMaclean AlexMaclean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry about this. Thanks!

@RKSimon RKSimon merged commit 72ffa79 into llvm:main Jun 26, 2025
9 checks passed
@RKSimon RKSimon deleted the nvptx-switch-build-fix branch June 26, 2025 19:13
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…lvm#145948)

llvm#145581 removed all the remaining special cases from the switch
statement leaving just the default, which MSVC complains about.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…lvm#145948)

llvm#145581 removed all the remaining special cases from the switch
statement leaving just the default, which MSVC complains about.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants