Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Suboptimal lowering of `mul x, 0b111....` when using SelectionDAG #48213

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR49244
Status NEW
Importance P normal
Reported by Min-Yih Hsu (minyihh@uci.edu)
Reported on 2021-02-17 23:55:41 -0800
Last modified on 2021-05-31 22:41:04 -0700
Version trunk
Hardware PC All
CC glaubitz@physik.fu-berlin.de, hasyimi@gatech.edu, llvm-bugs@lists.llvm.org, minyihh@uci.edu
Fixed by commit(s)
Attachments
Blocks PR48791
Blocked by
See also

As described in test/CodeGen/M68k/ASM/Arith/imul-neg.ll, when multiplying value x with 2^n - 1 integer, the result will be -x, which is preferred to be lowered to neg x instruction. However, SelectionDAG ISel will generate sub 0, x (FastISel doesn't have this problem though).

Quuxplusone commented 3 years ago

I'm pretty new to LLVM, and I'm trying to understand how mul x, 1111.. gets lowered to neg x. I notice that even when I run llc with -fast-isel flag, it still goes through DAGCombine pass, which is the one responsible for lowering mul x, 1111.. to sub 0, x. Shouldn't FastISel not go through DAGCombine?