llvm::ConstantFoldCompareInstOperands misses an optimization when it tries to constantFold a compare instruction containing addrspacecast instead of combination of ptrtoint and inttoptr. Adding the patched code snippet in the code would enable the pass to handle addrspacecast and constantFold the missing cases.
Attached is the reproducer. Let me know if there are any suggestions/comments.
Details
- Reviewers
majnemer llvm-commits
Diff Detail
Event Timeline
This needs a test case. Also, you need to upload a diff with more context. There are instructions here on how to do this.
Hi David,
I have already attached a test case in the summary section. Isn't that sufficient ?
Hi David,
Added the test case as a part of the patch as you suggested. Does this look okay ?
Thanks,
Tejas
Please include additional context in the diff.
test/Transforms/InstCombine/instCombineOptimizeAddrspaceCast.ll | ||
---|---|---|
8–26 ↗ | (On Diff #40553) | Can you try to make this test a little more targeted? |
Hi David,
Added some more context in both the .ll and cpp. I don't think the ll can be shortened more, this is the bare minimum needed to test.
Thanks
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1141 | Ideally it's best to submit the entire file containing your changes. I would do this as follows: git diff <previous_commit_id> HEAD -U99999 > my.patch | |
1142 | Maximize the 80 column line width here. | |
1147 | Your patch seems to be based on an older version of code. In the latest tip the signature of ConstantFoldCompareInstOperands does not use "TD". It uses DataLayout (DL) instead: return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI); | |
test/Transforms/InstCombine/instCombineOptimizeAddrspaceCast.ll | ||
1 ↗ | (On Diff #40807) | The test name does not need to contain "instCombine". It can simply be called OptimizeAddrspaceCast.ll |
I have made all the changes suggested by David, Meador and Mandeep. Can I commit this change now ?
Your test doesn't parse on trunk LLVM:
opt: <stdin>:14:32: error: expected comma after load's type
%2 = load i32 addrspace(4)** %ptr, align 8
Can you please include additional context in the diff, as requested above?
(See http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface for directions.)
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1144 | I'm not sure I understand why this is correct. My understanding of the semantics of addrspacecast is that it may change the integer value of the pointer ("It can be a no-op cast or a complex value modification, depending on the target and the address space pair"). Since icmp on pointers compares integer values ("If the operands are pointer typed, the pointer values are compared as if they were integers."), this transformation may change the result of the comparison. Am I missing something? | |
test/Transforms/InstCombine/OptimizeAddrspaceCast.ll | ||
27 | Any chance to reduce the test case? It looks very large, compared to what it's actually checking. |
Seems to be some extraneous spaces here.