New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misoptimization involving memset and store #35477
Comments
I believe this is a case of: store 3 cannot be merged into store 1, because the store 2 to Q mayalias P. The PartialStoreMerging we have doesn't take this into account I don't think. |
Thanks for cc'ing me, Dave. For reference, partial store merging was: I commandeered that patch, but I still don't know much about this pass. Let me see if I can take alias analysis into account, so we avoid this. |
Maybe a check of memoryIsNotModifiedBetween is all we need? Same as noop stores. It may not be the most efficient, but I think checks what we want. |
Sounds good to me...patch coming up. Thanks! |
Should this be a 6.00 blocker? |
Yes, I think so - it's a recently introduced miscompile. |
Thanks for elevating to a 6.0.0 blocker. LDC generates code that encounters this bug. The bug results in LDC failing its testsuite, so would be a blocker for releasing LDC linked to LLVM 6.0.0. (I haven't tried to make a testcase that would reproduce with Clang) |
Fixed in trunk: Leaving the bug open to allow baking time there and - assuming success - merging in the branch. |
*** Bug llvm/llvm-bugzilla-archive#35923 has been marked as a duplicate of this bug. *** |
I can confirm that the original D testcase now passes with LDC+LLVMtrunk. Thanks for the fix! (Sidenote: In the code, I read a TODO comment "Deal with [...] some mem intrinsics (if needed)". As you can see from the testcase IR, we generate a call to the memset intrinsic to set the padding bytes of structs to zero (padding bytes are put in arrays of i8). So for us, it'd be beneficial if the store merge code learns how to deal with that.) |
Thanks for verifying, Johan. Can you open a new bug report for the missed optimization? We don't want to lose track of that request when this report is closed. |
Merged in r324086.
Was a new bug filed? I'd like to close this. |
Closing - I've taken a shot at what I think the problem is with bug 36211. |
Extended Description
The
llvm5.ll
is the optimized (-O3) output of LLVM 5.0 opt of a simple testcase compiled by LDC. The testcase is setting %dt and %dt2 to the same value by different means, and asserts that they are equal indeed.llvm6.ll
is the output of opt 6.0.0 when optimizingllvm5.ll
:reproducer=
opt -O3 llvm5.ll -S -o llvm6.ll
.LLVM6.0 does a misoptimization and the assert fails.
Zooming in:
is optimized to
[Remark: I can see that perhaps endianness is tricky here. But actually, the LLVM optimizer itself converted the type of %dt2 to i64* (instead of %datum.DateTime*).]
The text was updated successfully, but these errors were encountered: