These don't always get folded because when the instructions are created the constants are obscured by artifacts, or other reasons.
Use it AArch64 post-legal combiner too.
Paths
| Differential D106776
[GlobalISel] Add a constant folding combine. ClosedPublic Authored by aemerson on Jul 25 2021, 3:10 PM.
Details Summary These don't always get folded because when the instructions are created the constants are obscured by artifacts, or other reasons. Use it AArch64 post-legal combiner too.
Diff Detail
Event TimelineHerald added subscribers: kerbowa, hiraditya, kristof.beyls and 3 others. · View Herald TranscriptJul 25 2021, 3:10 PM
Comment Actions Add a variant of replaceInstWithConstant taking APInt. It still seems convenient to have an int64_t version since that one builds the constant with the type of the DstOp, while we'd have to construct a correctly sized APInt in each call site if we replaced it. This revision is now accepted and ready to land.Jul 26 2021, 11:56 AM This revision was landed with ongoing or failed builds.Jul 26 2021, 2:54 PM Closed by commit rGc658b472f3e6: [GlobalISel] Add a constant folding combine. (authored by aemerson). · Explain Why This revision was automatically updated to reflect the committed changes. Comment Actions
For the AMDGPU fshl/fshr tests, the reason is that the foldable instructions are created during legalization, and the AMDGPU legalizer doesn't use CSEMIRBuilder yet. Comment Actions
Scratch that. The reason is that the constants are obscured by artifacts like G_ZEXT, which we don't constant fold (I previously tried that in D89392).
Revision Contents
Diff 361546 llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
llvm/include/llvm/Target/GlobalISel/Combine.td
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/lib/Target/AArch64/AArch64Combine.td
llvm/test/CodeGen/AArch64/GlobalISel/arm64-atomic-128.ll
llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-constant-fold.mir
llvm/test/CodeGen/AArch64/fold-global-offsets.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/fshl.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/fshr.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/saddsat.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/ssubsat.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/udiv.i32.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/urem.i32.ll
|
This looks like it could use replaceInstWithConstant; does it need APInt? (Or should that helper be changed to use APInt?)