[llvm] Introduce DIExpression::foldConstantMath() (PR #71718)
Shubham Sandeep Rastogi via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 11:08:23 PDT 2024
================
@@ -2011,6 +2010,347 @@ DIExpression::constantFold(const ConstantInt *CI) {
ConstantInt::get(getContext(), NewInt)};
}
+// Returns true if the Op is a DW_OP_constu.
+static bool isConstantVal(uint64_t Op) { return Op == dwarf::DW_OP_constu; }
+
+// Returns true if an operation and operand result in a No Op.
+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;
+ }
+}
+
+// Try to fold constant math operations and return the result if possible.
+static std::optional<uint64_t>
+foldOperationIfPossible(uint64_t Op, uint64_t Operand1, uint64_t Operand2) {
+ bool ResultOverflowed;
+ switch (Op) {
+ case dwarf::DW_OP_plus: {
+ auto Result = SaturatingAdd(Operand1, Operand2, &ResultOverflowed);
----------------
rastogishubham wrote:
AddOverflow needs a signed integer, we are dealing only with unsigned values, so that will not work
https://github.com/llvm/llvm-project/pull/71718
More information about the llvm-commits
mailing list