[PATCH] D124722: [InstCombine] extract(u[add|sub].with.overflow(X, C), 0) --> [add|sub](X, C)

Nicolas Abram via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 30 23:56:50 PDT 2022


nico-abram updated this revision to Diff 426270.

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

https://reviews.llvm.org/D124722

Files:
  llvm/test/Transforms/InstCombine/with_overflow.ll


Index: llvm/test/Transforms/InstCombine/with_overflow.ll
===================================================================
--- llvm/test/Transforms/InstCombine/with_overflow.ll
+++ llvm/test/Transforms/InstCombine/with_overflow.ll
@@ -478,6 +478,40 @@
   ret i1 %d
 }
 
+define i1 @uadd_res_ult_const_five_and_ov(i32 %x) nounwind {
+; CHECK-LABEL: @uadd_res_ult_const_five_and_ov(
+; CHECK-NEXT:    [[A:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[X:%.*]], i32 5)
+; CHECK-NEXT:    [[C:%.*]] = extractvalue { i32, i1 } [[A]], 0
+; CHECK-NEXT:    [[B:%.*]] = extractvalue { i32, i1 } [[A]], 1
+; CHECK-NEXT:    [[D:%.*]] = icmp ult i32 [[C]], 4
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[D]], [[B]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 5)
+  %c = extractvalue { i32, i1 } %a, 0
+  %b = extractvalue { i32, i1 } %a, 1
+  %d = icmp ult i32 %c, 4
+  %r = and i1 %d, %b
+  ret i1 %r
+}
+
+define i1 @uadd_res_ugt_smaller_const_or_ov(i32 %x) nounwind {
+; CHECK-LABEL: @uadd_res_ugt_smaller_const_or_ov(
+; CHECK-NEXT:    [[A:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[X:%.*]], i32 5)
+; CHECK-NEXT:    [[C:%.*]] = extractvalue { i32, i1 } [[A]], 0
+; CHECK-NEXT:    [[B:%.*]] = extractvalue { i32, i1 } [[A]], 1
+; CHECK-NEXT:    [[D:%.*]] = icmp ugt i32 [[C]], 4
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[D]], [[B]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 5)
+  %c = extractvalue { i32, i1 } %a, 0
+  %b = extractvalue { i32, i1 } %a, 1
+  %d = icmp ugt i32 %c, 4
+  %r = or i1 %d, %b
+  ret i1 %r
+}
+
 define { i32, i1 } @sadd_canonicalize_constant_arg0(i32 %x) nounwind {
 ; CHECK-LABEL: @sadd_canonicalize_constant_arg0(
 ; CHECK-NEXT:    [[A:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X:%.*]], i32 42)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124722.426270.patch
Type: text/x-patch
Size: 1869 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220501/2e7314d1/attachment.bin>


More information about the llvm-commits mailing list