[PATCH] [InstCombineCompares] Added shl optimization for the instruction - icmp ugt/ult/uge/ule (shl Const2, A), Const1

David Majnemer david.majnemer at gmail.com
Thu Nov 6 01:51:12 PST 2014


================
Comment at: test/Transforms/InstCombine/icmp.ll:1549-1555
@@ +1548,9 @@
+
+define i1 @shl_ugt_ap2_greater(i32 %a) {
+; CHECK-LABEL: @shl_ugt_ap2_greater(
+; CHECK-NEXT: ret i1 true
+  %shl = shl i32 498, %a
+  %cmp = icmp ugt i32 %shl, 123
+  ret i1 %cmp
+}
+
----------------
Consider when %a is 31: %shl will be 0 which will mean %cmp is actually false, not true.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1557-1588
@@ +1556,34 @@
+
+define i1 @shl_uge_ap2_greater(i32 %a) {
+; CHECK-LABEL: @shl_uge_ap2_greater(
+; CHECK-NEXT: ret i1 true
+  %shl = shl i32 498, %a
+  %cmp = icmp uge i32 %shl, 123
+  ret i1 %cmp
+}
+
+define i1 @shl_ult_ap2_greater(i32 %a) {
+; CHECK-LABEL: @shl_ult_ap2_greater(
+; CHECK-NEXT: ret i1 false
+  %shl = shl i32 498, %a
+  %cmp = icmp ult i32 %shl, 123
+  ret i1 %cmp
+}
+
+define i1 @shl_ule_ap2_greater(i32 %a) {
+; CHECK-LABEL: @shl_ule_ap2_greater(
+; CHECK-NEXT: ret i1 false
+  %shl = shl i32 498, %a
+  %cmp = icmp ule i32 %shl, 123
+  ret i1 %cmp
+}
+
+define i1 @shl_ugt_ap1_greater_1(i32 %a) {
+; CHECK-LABEL: @shl_ugt_ap1_greater_1(
+; CHECK-NEXT: %cmp = icmp ne i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ugt i32 %shl, 108
+  ret i1 %cmp
+}
+
----------------
These have similar problems to the previous test case.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1590-1597
@@ +1589,10 @@
+
+define i1 @shl_uge_ap1_greater_1(i32 %a) {
+; CHECK-LABEL: @shl_uge_ap1_greater_1(
+; CHECK-NEXT: %cmp = icmp ne i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp uge i32 %shl, 108
+  ret i1 %cmp
+}
+
----------------
Consider when %a is 31: %shl will be 0 which will mean %cmp should be false.

However, this transform would make %cmp true.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1599-1606
@@ +1598,10 @@
+
+define i1 @shl_ult_ap1_greater_1(i32 %a) {
+; CHECK-LABEL: @shl_ult_ap1_greater_1(
+; CHECK-NEXT: %cmp = icmp eq i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ult i32 %shl, 108
+  ret i1 %cmp
+}
+
----------------
Consider when %a is 30: %shl will be 0 which will mean %cmp should be true.

However, this transform would make %cmp false.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1608-1651
@@ +1607,45 @@
+
+define i1 @shl_ule_ap1_greater_1(i32 %a) {
+; CHECK-LABEL: @shl_ule_ap1_greater_1(
+; CHECK-NEXT: %cmp = icmp eq i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ule i32 %shl, 108
+  ret i1 %cmp
+}
+
+define i1 @shl_ugt_ap1_greater_2(i32 %a) {
+; CHECK-LABEL: @shl_ugt_ap1_greater_2(
+; CHECK-NEXT: %cmp = icmp ugt i32 %a, 1
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ugt i32 %shl, 152
+  ret i1 %cmp
+}
+
+define i1 @shl_uge_ap1_greater_2(i32 %a) {
+; CHECK-LABEL: @shl_uge_ap1_greater_2(
+; CHECK-NEXT: %cmp = icmp ne i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp uge i32 %shl, 152
+  ret i1 %cmp
+}
+
+define i1 @shl_ult_ap1_greater_2(i32 %a) {
+; CHECK-LABEL: @shl_ult_ap1_greater_2(
+; CHECK-NEXT: %cmp = icmp eq i32 %a, 0
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ult i32 %shl, 152
+  ret i1 %cmp
+}
+
+define i1 @shl_ule_ap1_greater_2(i32 %a) {
+; CHECK-LABEL: @shl_ule_ap1_greater_2(
+; CHECK-NEXT: %cmp = icmp ult i32 %a, 2
+; CHECK-NEXT: ret i1 %cmp
+  %shl = shl i32 76, %a
+  %cmp = icmp ule i32 %shl, 152
+  ret i1 %cmp
+}
----------------
I'm pretty sure these aren't correct transformations either.

http://reviews.llvm.org/D6131






More information about the llvm-commits mailing list