[all-commits] [llvm/llvm-project] 29f189: [InstCombine] Conditionally emit nowrap flags when...

Nikita Popov via All-commits all-commits at lists.llvm.org
Wed Apr 14 11:53:27 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 29f189f90d44a021dafc859b0db4def53b1b46a3
      https://github.com/llvm/llvm-project/commit/29f189f90d44a021dafc859b0db4def53b1b46a3
  Author: Mehrnoosh Heidarpour <mehrnoosh.heidarpour at huawei.com>
  Date:   2021-04-14 (Wed, 14 Apr 2021)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/test/Transforms/InstCombine/icmp-add.ll

  Log Message:
  -----------
  [InstCombine] Conditionally emit nowrap flags when combining two adds

Currently, the InstCombineCompare is combining two add operations
into a single add operation which always has a nsw flag, without
checking the conditions to see if this flag should be present
according to the original two add operations or not.

This patch will change the InstCombineCompare to emit the nsw or
nuw only when these flags are allowed to be generated according to
the original add operations and remove the possibility of applying
wrong optimization with passes that will perform on the IR later
in the pipeline.

To confirm that the current results are buggy and the results after
proposed patch are the correct IR the following examples from Alive2
are attached; the same results can be seen in the case of nuw flag
and nsw is just used as an example. The following link shows that
the generated IR with current LLVM is a buggy IR when none of the
original add operations have nsw flag.
https://alive2.llvm.org/ce/z/WGaDrm
The following link proves that the generated IR after the patch in
the former case is the correct IR.
https://alive2.llvm.org/ce/z/wQ7G_e

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




More information about the All-commits mailing list