[llvm] [Reassociate] Preserve NSW flags after expr tree rewriting (PR #93105)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue May 28 09:24:48 PDT 2024


dtcxzyw wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> 
>  You can test this locally with the following command:
> ```shell
> git-clang-format --diff af36fb00e32e43101b68b142cfc938af68ad5ffe b8e1d8d6faf8705c12958739975f01fef3ff2ea8 -- llvm/include/llvm/Transforms/Scalar/Reassociate.h llvm/lib/Transforms/Scalar/Reassociate.cpp
> ```
> 
>  View the diff from clang-format here.
> ```diff
> diff --git a/llvm/include/llvm/Transforms/Scalar/Reassociate.h b/llvm/include/llvm/Transforms/Scalar/Reassociate.h
> index 1ead59c619..b4c6cd480a 100644
> --- a/llvm/include/llvm/Transforms/Scalar/Reassociate.h
> +++ b/llvm/include/llvm/Transforms/Scalar/Reassociate.h
> @@ -70,8 +70,7 @@ struct OverflowTracking {
>    // Note: AllKnownNegative can be true in a case where one of the operands
>    // is negative, but one the operators is not NSW. AllKnownNegative should
>    // not be used independently of HasNSW
> -  OverflowTracking()
> -      : HasNUW(true), HasNSW(true), AllKnownNonNegative(true) {}
> +  OverflowTracking() : HasNUW(true), HasNSW(true), AllKnownNonNegative(true) {}
>  };
>  
>  class XorOpnd;
> diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
> index e7d18b2487..c903e47a93 100644
> --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
> +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
> @@ -651,8 +651,7 @@ static bool LinearizeExprTree(Instruction *I,
>      // Ensure the leaf is only output once.
>      It->second = 0;
>      Ops.push_back(std::make_pair(V, Weight));
> -    if (Opcode == Instruction::Add && Flags.AllKnownNonNegative &&
> -        Flags.HasNSW)
> +    if (Opcode == Instruction::Add && Flags.AllKnownNonNegative && Flags.HasNSW)
>        Flags.AllKnownNonNegative &= isKnownNonNegative(V, SimplifyQuery(DL));
>    }
>  
> ```

@akshayrdeodhar Can you fix this?


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


More information about the llvm-commits mailing list