[LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)
commita7554dfc222b13624426ebd6ef46e122b9c16ee7
authorYingwei Zheng <dtcxzyw2333@gmail.com>
Tue, 10 Sep 2024 01:19:39 +0000 (10 09:19 +0800)
committerTobias Hieta <tobias@hieta.se>
Tue, 1 Oct 2024 06:51:27 +0000 (1 08:51 +0200)
treede3de72aa10a98a35a6736c851dcdd3f44848547
parentb3731b36421e23737be2b4785700267b96c3241f
 [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)

After https://github.com/llvm/llvm-project/pull/92205, LoongArch ISel
selects `div.w` for `trunc i64 (sdiv i64 3202030857, (sext i32 X to
i64)) to i32`. It is incorrect since `3202030857` is not a signed 32-bit
constant. It will produce wrong result when `X == 2`:
https://alive2.llvm.org/ce/z/pzfGZZ

This patch adds additional `sexti32` checks to operands of
`PatGprGpr_32`.
Alive2 proof: https://alive2.llvm.org/ce/z/AkH5Mp

Fix #107414.

(cherry picked from commit a111f9119a5ec77c19a514ec09454218f739454f)
llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem.ll