[PATCH] D149033: [NFC]Fix 2 logic dead code

Kan Shengchen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 01:33:25 PDT 2023


skan added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5452
       // Get the exponent as a positive value.
       if ((int)Val < 0)
         Val = -Val;
----------------
skan wrote:
> craig.topper wrote:
> > XinWang10 wrote:
> > > skan wrote:
> > > > Shouldn't we remove the cast too?
> > > Sure, it should be.
> > What was wrong with the original code? The if wasn't meaningless, the cast made it a signed comparison. The unsigned type prevented the undefined behavior on Val = -Val.
> The original code has one issue. The return value of `RHSC->getSExtValue()` is `int64_t` and the minimum can be INT32_MIN, so the implicit cast at line 5454 may be a UB b/c `unsigned` can not represent the value. So, I fixed it in  rG8f966cedea594d9a91e585e88a80a42c04049e6c rather than reverted part of this patch.
Sorry, the original code has no issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149033/new/

https://reviews.llvm.org/D149033



More information about the llvm-commits mailing list