According https://reviews.llvm.org/D154953#inline-1516362, this fold
should be handled via simple range propagation.
Details
- Reviewers
goldstein.w.n nikic StephenFan arsenm
Diff Detail
Event Timeline
The proofs shouldn't only be for 32. It should use param C that you setup with assumes
llvm/test/Transforms/FunctionSpecialization/and-add-shl.ll | ||
---|---|---|
2 ↗ | (On Diff #546294) | Should the tests be in a different place? At the very least please precommit change of pass so we can more accurately see what's the result of the code change vs the pass change. |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | No else after return |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | Done, thanks |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | Imo should be Min = -Min; Max = -Max here instead of abs, think thats clearer given your negating. Can you also add a comment explaining why you're doing this. |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | apply your comments, thanks |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | Why are you inverting min/max here? |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | because this is a negative value. For example |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | I'm probably missing something (haven't really worked on ConstantRanges much), but since you are re-negating min/max isn't that already doing it? |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1501 | Yes, it is already done, but need swap it max/min values for negitive value |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1499 | Done, thanks |
Your patch is failing the ConstantRange unit tests. That's also the place to add test coverage for this change. This patch has no relation to FunctionSpecialization at all.
add condition OtherMax.ule(Max.abs().countl_zero()) to fix the failure cases reported in unittests/IR/ConstantRangeTest.cpp
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | You can either drop the !Neg here (my opinion) or drop the OtherMax.ule(Max...) in Neg definition. If OtherMax.ugt(...) is true, Neg will always be false. |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | thanks for your comment. the **OtherMax.ule(Max.abs()...)** in Neg definition has extra **abs()**, so this is different from the origin **OtherMax.ugt(...)** ? For example, if the Max type is i8, then -1 is 255, so Max.countl_zero() is 0, so the negative value Max will return getFull(), and the Neg condition is used to skip this blockage. |
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | I missed that but you still changed the codes. Was it not an issue afterall? |
I revert to use the previous change because there is an failure case Clang :: CodeGenOpenCL/shifts.cl
showed that the check getSingleElement() && isAllNegative() && OtherMax.ugt(Max.abs().countl_zero()) is necessary
llvm/lib/IR/ConstantRange.cpp | ||
---|---|---|
1485 | Yes, it is an issue, and the case Clang :: CodeGenOpenCL/shifts.c will failure. |
Add a negative test to show that the condition getSingleElement() is necessary for negative value, (derived from the C testcase in file Clang :: CodeGenOpenCL/shifts.cl)
I don't find this PR has some changes after rebasing. So I have a dig into it, and attached the negative test positiveShift32
I've implemented this myself in https://github.com/llvm/llvm-project/commit/4dd392fcd7847ef73233cd2f24623064ebc90a16.
bool Neg = getSingleElement && isAllNegative();