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@kalrayinc.com • [ https://www.kalrayinc.com/ | www.kalrayinc.com ]

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).

Hi Jason,
I’m using the “late” IfConverter.
Indeed I’m missing an implementation of ClobbersPredicate. However it seems this function assumes that the predicate is stored in a special system register (no surprise, the patch is arm oriented).
Our target stores predicates in general register. So I guess the only way out is to extend this method to accept the predicate conditions computed by analyzeBranch. I’ll give it a go.
Many thanks for the pointer.

Diogo Sampaio
Senior Compiler Engineer • Kalray
Phone:
dsampaio@kalrayinc.comwww.kalrayinc.com


Kalray logo

Intelligent Data Processing
From Cloud to Edge

Please consider the environment before printing this e-mail.
This message contains information that may be privileged or confidential and is the property of Kalray S.A. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.