[llvm] Introduce DIExpression::foldConstantMath() (PR #71718)
Shubham Sandeep Rastogi via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 09:00:07 PST 2023
================
@@ -1998,6 +1997,286 @@ DIExpression::constantFold(const ConstantInt *CI) {
ConstantInt::get(getContext(), NewInt)};
}
+static bool isConstantVal(uint64_t Op) {
+ return Op == dwarf::DW_OP_constu || Op == dwarf::DW_OP_consts;
+}
+
+static bool isNeutralElement(uint64_t Op, uint64_t Val) {
+ switch (Op) {
+ case dwarf::DW_OP_plus:
+ case dwarf::DW_OP_minus:
+ case dwarf::DW_OP_shl:
+ case dwarf::DW_OP_shr:
+ return Val == 0;
+ case dwarf::DW_OP_mul:
+ case dwarf::DW_OP_div:
+ return Val == 1;
+ default:
+ return false;
----------------
rastogishubham wrote:
I am not sure why that is odd, the operator passed to it can be anything, what if it is a sequence of
`DW_OP_constu, <const>, DW_OP_LLVM_arg, <arg1>, DW_OP_plus`
Op1 is DW_OP_constu and Op2 is DW_OP_LLVM_arg, so `isNeutralElement` can be called with a subsequence of `isNeutralElement(DW_OP_LLVM_arg,<const>)` which is why the default case exists
https://github.com/llvm/llvm-project/pull/71718
More information about the llvm-commits
mailing list