[AArch64] Fix comparison peephole opt with non-0/1 immediate (PR51476)
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 14 Aug 2021 21:35:27 +0000 (23:35 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 15 Aug 2021 10:35:52 +0000 (12:35 +0200)
commit81b106584f2baf33e09be2362c35c1bf2f6bfe94
treea8a62c018f288314b19651dafa4b1437c0aa8f2a
parent49de6070a2b7a9bb88ff7c935fea5176b1d9255f
[AArch64] Fix comparison peephole opt with non-0/1 immediate (PR51476)

This is a non-intrusive fix for
https://bugs.llvm.org/show_bug.cgi?id=51476 intended for backport
to the 13.x release branch. It expands on the current hack by
distinguishing between CmpValue of 0, 1 and 2, where 0 and 1 have
the obvious meaning and 2 means "anything else". The new optimization
from D98564 should only be performed for CmpValue of 0 or 1.

For main, I think we should switch the analyzeCompare() and
optimizeCompare() APIs to use int64_t instead of int, which is in
line with MachineOperand's notion of an immediate, and avoids this
problem altogether.

Differential Revision: https://reviews.llvm.org/D108076
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/test/CodeGen/AArch64/csinc-cmp-removal.mir
llvm/test/CodeGen/AArch64/pr51476.ll [new file with mode: 0644]