[TypePromotion] Extend TypePromotion::isSafeWrap
authorDavid Green <david.green@arm.com>
Sun, 14 Nov 2021 11:18:31 +0000 (11:18 +0000)
committerDavid Green <david.green@arm.com>
Sun, 14 Nov 2021 11:18:31 +0000 (11:18 +0000)
commit355ee18c5df9364f315f2bfad1793dd54efe6c9b
tree59d9a0d03488e15572552c01b7e15682322981e8
parent5b4bfd8c2415cb38983a56007bb424e063778460
[TypePromotion] Extend TypePromotion::isSafeWrap

This modifies the preconditions of TypePromotion's isSafeWrap
method, to allow it to work from all constants from the ICmp.
Using the code:
  %a = add %x, C1
  %c = icmp ult %a, C2

According to Alive, we can prove that is equivalent to
icmp ult (add zext(%x), sext(C1)), zext(C2)  given
C1 <=s 0 and C1 >s C2.
https://alive2.llvm.org/ce/z/CECYZB
Which is similar to what is already present. We can also
prove icmp ult (add zext(%x), sext(C1)), sext(C2) given
C1 <=s 0 and C1 <=s C2.
https://alive2.llvm.org/ce/z/KKgyeL

The PrepareWrappingAdds method was removed, and the
constants are now altered to sext or zext directly as
required by the above methods.

Differential Revision: https://reviews.llvm.org/D113678
llvm/lib/CodeGen/TypePromotion.cpp
llvm/test/CodeGen/AArch64/and-mask-removal.ll
llvm/test/CodeGen/AArch64/typepromotion-overflow.ll
llvm/test/Transforms/TypePromotion/ARM/casts.ll
llvm/test/Transforms/TypePromotion/ARM/clear-structures.ll
llvm/test/Transforms/TypePromotion/ARM/icmps.ll
llvm/test/Transforms/TypePromotion/ARM/wrapping.ll