[PATCH] D59218: [LSR] Fix signed overflow in GenerateCrossUseConstantOffsets.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 05:05:11 PDT 2019


fhahn marked an inline comment as done.
fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:4152
+        //        See PR41034.
+        Imms.lower_bound(((uint64_t)Imms.begin()->first + std::prev(Imms.end())->first) /
                          2)
----------------
efriedma wrote:
> This code is trying to compute (x+y)/2.  Mathematically, this can't overflow, so this shouldn't require a bitwidth to produce a meaningful result.
Unless I am missing something, the cast addresses a potential overflow for the x + y part of the expression. Running the attached test with opt+ubsan crashes here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59218





More information about the llvm-commits mailing list