[all-commits] [llvm/llvm-project] 51e9f3: [BasicAA] Use saturating multiply on range if nsw

Nikita Popov via All-commits all-commits at lists.llvm.org
Tue Nov 2 12:31:53 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 51e9f336030cc3892950763f9179e25fa582e3b9
      https://github.com/llvm/llvm-project/commit/51e9f336030cc3892950763f9179e25fa582e3b9
  Author: Nikita Popov <nikita.ppv at gmail.com>
  Date:   2021-11-02 (Tue, 02 Nov 2021)

  Changed paths:
    M llvm/lib/Analysis/BasicAliasAnalysis.cpp
    M llvm/test/Analysis/BasicAA/assume-index-positive.ll

  Log Message:
  -----------
  [BasicAA] Use saturating multiply on range if nsw

If we know that the var * scale multiplication is nsw, we can use
a saturating multiplication on the range (as a good approximation
of an nsw multiply). This recovers some cases where the fix from
D112611 is unnecessarily strict. (This can be further strengthened
by using a saturating add, but we currently don't track all the
necessary information for that.)

This exposes an issue in our NSW tracking for multiplies. The code
was assuming that (X +nsw Y) *nsw Z results in
(X *nsw Z) +nsw (Y *nsw Z) -- however, it is possible that the
distributed multiplications overflow, even if the non-distributed
one does not. We should discard the nsw flag if the the offset is
non-zero. If we just have (X *nsw Y) *nsw Z then concluding
X *nsw (Y *nsw Z) is fine.

Differential Revision: https://reviews.llvm.org/D112848




More information about the All-commits mailing list