InstCombine: merge constants in both operands of icmp.
[oota-llvm.git] / test / Transforms / InstCombine / icmp.ll
index 12a4744cc0feb05825409485d7c860b9b0e9a097..2e3ff24f6ba2cfaf721f3ea6b0407af75f6ee2be 100644 (file)
@@ -1356,3 +1356,56 @@ define i1 @icmp_ashr_ashr_ne(i32 %a, i32 %b) nounwind {
  %z = icmp ne i32 %x, %y
  ret i1 %z
 }
+
+; CHECK-LABEL: icmp_add_const_const1
+; CHECK: %cmp = icmp slt i32 %x, -10
+; CHECK-NOT: %add = add nsw i32 %x, 10
+define i32 @icmp_add_const_const1(i32 %x) nounwind ssp uwtable {
+entry:
+  %add = add nsw i32 %x, 10
+  %cmp = icmp slt i32 %add, 0
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}
+
+; CHECK-LABEL: icmp_add_const_const2
+; CHECK: %cmp = icmp slt i32 %x, -10
+; CHECK-NOT: %add = add nsw i32 %x, 10
+define i32 @icmp_add_const_const2(i32 %x) nounwind ssp uwtable {
+entry:
+  %add = add nsw i32 10, %x
+  %cmp = icmp sgt i32 0, %add
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}
+
+; CHECK-LABEL: icmp_add_const_const3
+; CHECK: %cmp = icmp slt i32 %x, 20
+; CHECK-NOT: %sub = add nsw i32 %x, -10
+define i32 @icmp_add_const_const3(i32 %x) nounwind ssp uwtable {
+entry:
+  %add = add nsw i32 -10, %x
+  %cmp = icmp sgt i32 10, %add
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}
+
+; CHECK-LABEL: icmp_add_const_intmin
+; CHECK: %cmp = icmp ne i32 %x, 2147483638
+define i32 @icmp_add_const_intmin(i32 %x) nounwind ssp uwtable {
+entry:
+  %add = add nsw i32 %x, 10
+  %cmp = icmp sgt i32 %add, -2147483648
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}
+
+; CHECK-LABEL: icmp_add_const_intmax
+; CHECK: %cmp = icmp ne i32 %x, 2147483637
+define i32 @icmp_add_const_intmax(i32 %x) nounwind ssp uwtable {
+entry:
+  %add = add nsw i32 %x, 10
+  %cmp = icmp slt i32 %add, 2147483647
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}