support for division by constant in APInt

In lib/CodeGen/SelectionDAG/TargetLowering.cpp there are some
functions magic() and magicu() that support optimising division by a
constant. I'd like to use these functions in an LLVM FunctionPass that
I'm working on. The attached patch moves these functions out of
TargetLowering.cpp and into the APInt class, so that I can reuse them
in my pass. What do you think?

It looks to me like these functions were copied straight out of
"Hacker's Delight", Henry S. Warren, Jr., so I added a comment
acknowledging that.

Thanks,
Jay.

patch.magic (9.39 KB)

The patch looks fine to me, does it pass regression tests etc? If so, please apply, or contact me off list if you don't yet have commit access. Thanks Jay!

-Chris

The patch looks fine to me, does it pass regression tests etc?

Yes, I've just run a successful "make" in the test-suite module. It
took hours! Is there a smaller set of regression tests I could run for
changes like this in future?

Thanks,
Jay.

“make unittests” is a smaller set of tests, but given that it doesn’t have particularly high coverage, it shouldn’t be the only tests you run.

There are unittests for APInt, but they wouldn’t cover a refactoring change such as this one. Please feel free to add a unittest with your change.

The patch looks fine to me, does it pass regression tests etc?

Yes, I’ve just run a successful “make” in the test-suite module. It
took hours! Is there a smaller set of regression tests I could run for
changes like this in future?

“make unittests” is a smaller set of tests, but given that it doesn’t have particularly high coverage, it shouldn’t be the only tests you run.

There are unittests for APInt, but they wouldn’t cover a refactoring change such as this one. Please feel free to add a unittest with your change.

‘make check’ runs regression tests.

You can also run a subset of llvm-test (test-suite), but its always better if you can run all of them.

-Tanya

'make check' runs regression tests.

Thanks - that's what I was missing! For what it's worth, my patch also
passes these regression tests.

Thanks,
Jay.

The patch looks fine to me, does it pass regression tests etc? If so,
please apply, or contact me off list if you don't yet have commit
access. Thanks Jay!

Committed here:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090427/076916.html

Thanks!
Jay.