[llvm] Introduce DIExpression::foldConstantMath() (PR #71718)

Paul T Robinson via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 09:13:59 PDT 2024


================
@@ -3120,6 +3120,285 @@ TEST_F(DIExpressionTest, get) {
   EXPECT_EQ(N0WithPrependedOps, N2);
 }
 
+TEST_F(DIExpressionTest, Fold) {
+
+  // Remove a No-op DW_OP_plus_uconst from an expression.
+  SmallVector<uint64_t, 8> Ops = {dwarf::DW_OP_plus_uconst, 0};
+  auto *Expr = DIExpression::get(Context, Ops);
+  auto *E = Expr->foldConstantMath();
+  SmallVector<uint64_t, 8> ResOps;
+  auto *ResExpr = DIExpression::get(Context, ResOps);
+  EXPECT_EQ(E, ResExpr);
+
+  // Remove a No-op add from an expression.
+  Ops[0] = dwarf::DW_OP_constu;
+  Ops[1] = 0;
+  Ops.push_back(dwarf::DW_OP_plus);
----------------
pogo59 wrote:

I'd prefer to see `Ops` cleared and start over from scratch each time. It makes each test independent of what went before, so each individual case will be easier to read (not dependent on previous cases) and future changes to the test code will be easier. The performance difference should be undetectable.

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


More information about the llvm-commits mailing list