[AArch64] Fixes ADD/SUB opt bug and abstracts shared behavior in MIPeepholeOpt...
[AArch64] Fixes ADD/SUB opt bug and abstracts shared behavior in MIPeepholeOpt for ADD, SUB, and AND. This fixes a bug where (SUBREG_TO_REG 0 (MOVi32imm <negative-number>) sub_32) would generate invalid code since the top 32-bits were not zeroed when inspecting the immediate value. A new test was added for this case. Change to abstract shared behavior in MIPeepholeOpt. Both visitAND and visitADDSUB attempt to split an RR instruction with an immediate operand into two RI instructions with the immediate split. The differing behavior lies in how the immediate is split into two pieces and how the new instructions are built. The rest of the behavior (adding new VRegs, checking for the MOVImm, constraining reg classes, removing old intructions) are shared between the operations. The new helper function splitTwoPartImm implements the shared behavior and delegates differing behavior to two function objects passed by the caller. One function object splits the immediate into two values and returns the opcode to use if it is a valid split. The other function object builds the new instructions. I felt this abstraction would help since I believe it will help reduce the code repetition when adding new instructions of the pattern, such as SUBS for this conditional optimization. Tested it locally by running check all with compiler-rt, mlir, clang-tools-extra, flang, llvm, and clang enabled. Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D118000
Loading
Please sign in to comment