This is a issue found when investigate https://reviews.llvm.org/D60395.
exact flag is missing when opt combine 0 - (X sdiv C) -> (X sdiv -C)
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Looks good, but a question re tests.
---------------------------------------- Optimization: zz Precondition: ((C != 1) && (C != -128)) %div = sdiv exact i8 %x, C %r = sub i8 0, %div => %r = sdiv exact i8 %x, -C Done: 1 Optimization is correct!
llvm/test/Transforms/InstCombine/div.ll | ||
---|---|---|
763 ↗ | (On Diff #194093) | Please add more tests.
|
please precommit the tests
llvm/test/Transforms/InstCombine/div.ll | ||
---|---|---|
783 ↗ | (On Diff #194101) | tests are faulty, contain nsw despite the name |
Thanks for your comments Roman @lebedev.ri . Updated.
llvm/test/Transforms/InstCombine/div.ll | ||
---|---|---|
783 ↗ | (On Diff #194101) | oops. fixed. |
LG
llvm/test/Transforms/InstCombine/div.ll | ||
---|---|---|
809 ↗ | (On Diff #194107) | test name is @test_exact_nonsw_noexact |
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp | ||
---|---|---|
1696 | Uhm. CC @spatel |
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp | ||
---|---|---|
1696 | Yes, if this patch has not been reverted yet, it probably should be. It's not correct for arbitrary vector constants. We can either limit this to splat constants (m_APInt) or do the more involved element-by-element check. If the divisor has an undef element, we have immediate UB, so anything goes. But we might want to do something better? I haven't looked at this patch closely yet. |
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp | ||
---|---|---|
1696 | Note that *this* patch only fixed propagation of exact. |
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp | ||
---|---|---|
1696 | ... and it won't be possible to revert the original patch, since it is here for 9+ years. |
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp | ||
---|---|---|
1696 |
Uhm.
So, this is not related to this patch specifically, but i think isOneValue() check is incorrect,
and may be causing miscompiles: https://godbolt.org/z/CmAslh <- i don't think @test_exact_vec should be folded?
I think you want to add a isNotOneValue().
Also, is this fold valid for undef elements?
CC @spatel