Diogo Sampaio via llvm-dev
2021-Sep-24 15:53 UTC
[llvm-dev] If-converter breaking condition data dependency
Hi, I'm trying to use if-converter to generate conditional load instructions. However I'm acing a data-dependency issue such as this one: The original code would output as this: compw.eq $r0 = $r1, $r0 <= condition is stored in r0 ;; cb.even $r0 ? .LBB72_9 <= branch if r0 is even ;; ld $r0 = 16[$r20] <= only loads if r0 is odd ;; ld $r20 = 8[$r0] <= only loads if r0 is odd ;; .LBB72_9: if-converter would change it to this: compw.eq $r0 = $r1, $r0 <= same condition in same register ;; ld.odd $r0 ? $r0 = 16[$r20] <= ko. The condition is overwritten. ;; ld.odd $r0 ? $r20 = 8[$r0] <= ko. Load occurs depending on the new loaded value. In none of the TargetInstructionInfo hooks we obtain both the basic block and branch conditions to detect this break of data dependency, although I imagine the if-converter should be the one doing so. At best, isProfitableToIfCvt should also receive the branch conditions, so it could detect this case. Am I missing something? Did anyone else face such issue? Btw, we're still using llvm 12.0.1. Thanks in advance. Diogo Sampaio Senior Compiler Engineer • Kalray dsampaio at kalrayinc.com • [ https://www.kalrayinc.com/ | www.kalrayinc.com ]
Jason Eckhardt via llvm-dev
2021-Sep-24 19:40 UTC
[llvm-dev] If-converter breaking condition data dependency
>In none of the TargetInstructionInfo hooks we obtain both the basic block and >branch conditions to detect this break of data dependency, although I imagine >the if-converter should be the one doing so. > >At best, isProfitableToIfCvt should also receive the branch conditions, so it >could detect this case.Which if-converter pass are you using? There is the "late" IfConverter pass and the "early" EarlyIfPredicator pass. In either case, the legality checks are not performed by isProfitableToIfCvt. Off the top of my head, I'd guess that if you are using the IfConverter, you might double-check your implementation of TII::ClobbersPredicate or trace through its callers on your example. If you are using EarlyIfPredicator, you might check SSAIfConv::canPredicateInstrs (and its helper SSAIfConv::InstrDependenciesAllowIfConv). ________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Diogo Sampaio via llvm-dev <llvm-dev at lists.llvm.org> Sent: Friday, September 24, 2021 10:53 AM To: llvm-dev <llvm-dev at lists.llvm.org> Subject: [llvm-dev] If-converter breaking condition data dependency External email: Use caution opening links or attachments Hi, I'm trying to use if-converter to generate conditional load instructions. However I'm acing a data-dependency issue such as this one: The original code would output as this: compw.eq $r0 = $r1, $r0 <= condition is stored in r0 ;; cb.even $r0 ? .LBB72_9 <= branch if r0 is even ;; ld $r0 = 16[$r20] <= only loads if r0 is odd ;; ld $r20 = 8[$r0] <= only loads if r0 is odd ;; .LBB72_9: if-converter would change it to this: compw.eq $r0 = $r1, $r0 <= same condition in same register ;; ld.odd $r0 ? $r0 = 16[$r20] <= ko. The condition is overwritten. ;; ld.odd $r0 ? $r20 = 8[$r0] <= ko. Load occurs depending on the new loaded value. In none of the TargetInstructionInfo hooks we obtain both the basic block and branch conditions to detect this break of data dependency, although I imagine the if-converter should be the one doing so. At best, isProfitableToIfCvt should also receive the branch conditions, so it could detect this case. Am I missing something? Did anyone else face such issue? Btw, we're still using llvm 12.0.1. Thanks in advance. Diogo Sampaio Senior Compiler Engineer • Kalray dsampaio at kalrayinc.com • [ https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kalrayinc.com%2F&data=04%7C01%7Cjeckhardt%40nvidia.com%7C4d6e38fe8f8c4bb36fd308d97f7381f1%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637680957074749887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=H1EyRiaE4sIHi5jGbOBIzPkaBmMQdCu%2B0%2FTU6o1V2eE%3D&reserved=0 | https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kalrayinc.com%2F&data=04%7C01%7Cjeckhardt%40nvidia.com%7C4d6e38fe8f8c4bb36fd308d97f7381f1%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637680957074749887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=MvqpedZGdiKhXiQ4aM88wLhJ5Z1GtYMM7eTCx9QIRHQ%3D&reserved=0 ] _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev&data=04%7C01%7Cjeckhardt%40nvidia.com%7C4d6e38fe8f8c4bb36fd308d97f7381f1%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637680957074749887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=gkvPjtISQhONUYJMhiXCGhOVQv8diMTLxxL4dlnryVI%3D&reserved=0 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210924/435162f8/attachment.html>