[llvm] r346719 - [InstCombine] add rotate variants that include select; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 12 15:58:59 PST 2018
Author: spatel
Date: Mon Nov 12 15:58:59 2018
New Revision: 346719
URL: http://llvm.org/viewvc/llvm-project?rev=346719&view=rev
Log:
[InstCombine] add rotate variants that include select; NFC
Modified:
llvm/trunk/test/Transforms/InstCombine/rotate.ll
Modified: llvm/trunk/test/Transforms/InstCombine/rotate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/rotate.ll?rev=346719&r1=346718&r2=346719&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/rotate.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/rotate.ll Mon Nov 12 15:58:59 2018
@@ -309,3 +309,87 @@ define i8 @rotateleft_8_neg_mask_wide_am
ret i8 %ret
}
+; TODO: Convert select pattern to masked shift that ends in 'or'.
+
+define i32 @rotr_select(i32 %x, i32 %shamt) {
+; CHECK-LABEL: @rotr_select(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SHAMT:%.*]], 0
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 32, [[SHAMT]]
+; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[X:%.*]], [[SHAMT]]
+; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X]], [[SUB]]
+; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHR]], [[SHL]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[OR]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %cmp = icmp eq i32 %shamt, 0
+ %sub = sub i32 32, %shamt
+ %shr = lshr i32 %x, %shamt
+ %shl = shl i32 %x, %sub
+ %or = or i32 %shr, %shl
+ %r = select i1 %cmp, i32 %x, i32 %or
+ ret i32 %r
+}
+
+; TODO: Convert select pattern to masked shift that ends in 'or'.
+
+define i8 @rotr_select_commute(i8 %x, i8 %shamt) {
+; CHECK-LABEL: @rotr_select_commute(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SHAMT:%.*]], 0
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 8, [[SHAMT]]
+; CHECK-NEXT: [[SHR:%.*]] = lshr i8 [[X:%.*]], [[SHAMT]]
+; CHECK-NEXT: [[SHL:%.*]] = shl i8 [[X]], [[SUB]]
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[SHL]], [[SHR]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i8 [[X]], i8 [[OR]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %cmp = icmp eq i8 %shamt, 0
+ %sub = sub i8 8, %shamt
+ %shr = lshr i8 %x, %shamt
+ %shl = shl i8 %x, %sub
+ %or = or i8 %shl, %shr
+ %r = select i1 %cmp, i8 %x, i8 %or
+ ret i8 %r
+}
+
+; TODO: Convert select pattern to masked shift that ends in 'or'.
+
+define i16 @rotl_select(i16 %x, i16 %shamt) {
+; CHECK-LABEL: @rotl_select(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[SHAMT:%.*]], 0
+; CHECK-NEXT: [[SUB:%.*]] = sub i16 16, [[SHAMT]]
+; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[X:%.*]], [[SUB]]
+; CHECK-NEXT: [[SHL:%.*]] = shl i16 [[X]], [[SHAMT]]
+; CHECK-NEXT: [[OR:%.*]] = or i16 [[SHR]], [[SHL]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i16 [[X]], i16 [[OR]]
+; CHECK-NEXT: ret i16 [[R]]
+;
+ %cmp = icmp eq i16 %shamt, 0
+ %sub = sub i16 16, %shamt
+ %shr = lshr i16 %x, %sub
+ %shl = shl i16 %x, %shamt
+ %or = or i16 %shr, %shl
+ %r = select i1 %cmp, i16 %x, i16 %or
+ ret i16 %r
+}
+
+; TODO: Convert select pattern to masked shift that ends in 'or'.
+
+define i64 @rotl_select_commute(i64 %x, i64 %shamt) {
+; CHECK-LABEL: @rotl_select_commute(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[SHAMT:%.*]], 0
+; CHECK-NEXT: [[SUB:%.*]] = sub i64 64, [[SHAMT]]
+; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[X:%.*]], [[SUB]]
+; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[X]], [[SHAMT]]
+; CHECK-NEXT: [[OR:%.*]] = or i64 [[SHL]], [[SHR]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i64 [[X]], i64 [[OR]]
+; CHECK-NEXT: ret i64 [[R]]
+;
+ %cmp = icmp eq i64 %shamt, 0
+ %sub = sub i64 64, %shamt
+ %shr = lshr i64 %x, %sub
+ %shl = shl i64 %x, %shamt
+ %or = or i64 %shl, %shr
+ %r = select i1 %cmp, i64 %x, i64 %or
+ ret i64 %r
+}
+
More information about the llvm-commits
mailing list