diff options
Diffstat (limited to 'llvm/test/Transforms/InstCombine/rotate.ll')
-rw-r--r-- | llvm/test/Transforms/InstCombine/rotate.ll | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/llvm/test/Transforms/InstCombine/rotate.ll b/llvm/test/Transforms/InstCombine/rotate.ll index 36e485158d63..4c77d44f024f 100644 --- a/llvm/test/Transforms/InstCombine/rotate.ll +++ b/llvm/test/Transforms/InstCombine/rotate.ll @@ -435,11 +435,11 @@ define i8 @rotate_right_8bit(i8 %v, i3 %shift) { ret i8 %conv2 } -; The shifted value does not need to be a zexted value; here it is masked. +; The right-shifted value does not need to be a zexted value; here it is masked. ; The shift mask could be less than the bitwidth, but this is still ok. -define i8 @rotate_right_commute_8bit(i32 %v, i32 %shift) { -; CHECK-LABEL: @rotate_right_commute_8bit( +define i8 @rotate_right_commute_8bit_unmasked_shl(i32 %v, i32 %shift) { +; CHECK-LABEL: @rotate_right_commute_8bit_unmasked_shl( ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[SHIFT:%.*]] to i8 ; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], 3 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[V:%.*]] to i8 @@ -456,6 +456,30 @@ define i8 @rotate_right_commute_8bit(i32 %v, i32 %shift) { ret i8 %conv2 } +; TODO: +; The left-shifted value does not need to be masked at all. + +define i8 @rotate_right_commute_8bit(i32 %v, i32 %shift) { +; CHECK-LABEL: @rotate_right_commute_8bit( +; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHIFT:%.*]], 3 +; CHECK-NEXT: [[CONV:%.*]] = and i32 [[V:%.*]], 255 +; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[CONV]], [[AND]] +; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 8, [[AND]] +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[V]], [[SUB]] +; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHR]], [[SHL]] +; CHECK-NEXT: [[CONV2:%.*]] = trunc i32 [[OR]] to i8 +; CHECK-NEXT: ret i8 [[CONV2]] +; + %and = and i32 %shift, 3 + %conv = and i32 %v, 255 + %shr = lshr i32 %conv, %and + %sub = sub i32 8, %and + %shl = shl i32 %v, %sub + %or = or i32 %shr, %shl + %conv2 = trunc i32 %or to i8 + ret i8 %conv2 +} + ; If the original source does not mask the shift amount, ; we still do the transform by adding masks to make it safe. |