[PATCH] D76201: [TargetLowering] Only demand a rotation's modulo amount bits

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 07:35:35 PDT 2020


aykevl added a comment.

See my inline comment. I only checked `rol8` on AVR but I think the same applies to `ror8`. Basically it seems like the transformation is correct but will make the operation unacceptably slower.

I'm not sure I can help you fix this, I'm still very new to backend development.



================
Comment at: llvm/test/CodeGen/AVR/rot.ll:7
 define i8 @rol8(i8 %val, i8 %amt) {
-  ; CHECK:      andi r22, 7
-
----------------
If I'm reading this IR, correctly, it does a rotate left just as the name implies.
I think the transformation here is correct in that it will still produce the same output, but without the mask the rotate may take a lot longer. I think the AVR assembly could be written as the following pseudocode (assume 8-bit unsigned integers everywhere):

```
// r24 = val
// r22 = amt
def rol8(r24, r22):
    r22 &= 7           // this mask is removed by this patch
    if r22 == 0:
        return r24     // return value (LBB0_2)
    while 1:
        r24 = (r24 << 1) | (r24 >> 7) // rotate r24 left by 1 (lsl, adc)
        r22 -= 1
        if r22 == 0:   // brne .LBB0_1
            return r24 // .LBB0_2, ret
```

So if you're calling `rol8(x, 200)` it will take 200 iterations to rotate a number.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76201/new/

https://reviews.llvm.org/D76201





More information about the llvm-commits mailing list