[Mlir-commits] [mlir] [emitc] Support translate switchop with argument of expressionop (PR #123701)

Matthias Gehre llvmlistbot at llvm.org
Tue Jan 21 00:35:16 PST 2025


================
@@ -882,3 +882,77 @@ func.func @emitc_switch_ui64() {
   }
   return
 }
+
+// CPP-DEFAULT-LABEL: void emitc_switch_expression() {
+// CPP-DEFAULT:         int64_t v1 = 42;
+// CPP-DEFAULT:         int64_t v2 = 24;
+// CPP-DEFAULT:         switch ((v1 + v2) * v2) {
+// CPP-DEFAULT:         case 2: {
+// CPP-DEFAULT:           int32_t v3 = func_b();
+// CPP-DEFAULT:           break;
+// CPP-DEFAULT:         }
+// CPP-DEFAULT:         case 5: {
+// CPP-DEFAULT:           int32_t v4 = func_a();
+// CPP-DEFAULT:           break;
+// CPP-DEFAULT:         }
+// CPP-DEFAULT:         default: {
+// CPP-DEFAULT:           float v5 = 4.200000000e+01f;
+// CPP-DEFAULT:           func2(v5);
+// CPP-DEFAULT:           break;
+// CPP-DEFAULT:         }
+// CPP-DEFAULT:         }
+// CPP-DEFAULT:         return;
+// CPP-DEFAULT:       }
+
+// CPP-DECLTOP-LABEL: void emitc_switch_expression() {
+// CPP-DECLTOP:         int64_t v1;
+// CPP-DECLTOP:         int64_t v2;
+// CPP-DECLTOP:         float v3;
+// CPP-DECLTOP:         int32_t v4;
+// CPP-DECLTOP:         int32_t v5;
+// CPP-DECLTOP:         v1 = 42;
+// CPP-DECLTOP:         v2 = 24;
+// CPP-DECLTOP:         switch ((v1 + v2) * v2) {
+// CPP-DECLTOP:         case 2: {
+// CPP-DECLTOP:           v4 = func_b();
+// CPP-DECLTOP:           break;
+// CPP-DECLTOP:         }
+// CPP-DECLTOP:         case 5: {
+// CPP-DECLTOP:           v5 = func_a();
+// CPP-DECLTOP:           break;
+// CPP-DECLTOP:         }
+// CPP-DECLTOP:         default: {
+// CPP-DECLTOP:           v3 = 4.200000000e+01f;
+// CPP-DECLTOP:           func2(v3);
+// CPP-DECLTOP:           break;
+// CPP-DECLTOP:         }
+// CPP-DECLTOP:         }
+// CPP-DECLTOP:         return;
+// CPP-DECLTOP:       }
+
+func.func @emitc_switch_expression() {
----------------
mgehre-amd wrote:

Thanks for the fix!

Could you please minimize the test case to the smallest one that still shows the issue?
I.e. shorten the expression (`emitc.neg` maybe), reduce the number of cases and remove the code from the bodies of the cases.


https://github.com/llvm/llvm-project/pull/123701


More information about the Mlir-commits mailing list