[PATCH] D141022: [SelectionDAG] Improve codegen for udiv by constant if any divisors are 1.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 18:35:19 PST 2023


craig.topper created this revision.
craig.topper added reviewers: lebedev.ri, spatel, RKSimon, efriedma.
Herald added subscribers: StephenFan, ecnelises, steven.zhang, pengfei, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.

If the divisor is 1, the magic algorithm does not return a correct
result and we end up using a select to pick the numerator for those
elements at the end.

Therefore we can use undef for that element of the earlier operations
when the divisor is 1. We sometimes get this through SimplifyDemandedVectorElts,
but not always. Definitely seems like we don't if the NPQ fixup is used.

Unfortunately, DAGCombiner is unable to fold srl X, <0, undef> to X so
I had to add flags to avoid emitting the srl unless one of the shift
amounts is non-zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141022

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.ll
  llvm/test/CodeGen/X86/combine-udiv.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141022.486442.patch
Type: text/x-patch
Size: 5784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230105/79dc1c81/attachment.bin>


More information about the llvm-commits mailing list