[InstSimplify] Handle some overflow intrinsics in InstSimplify
This change does a few things:
- Move some InstCombine transforms to InstSimplify
- Run SimplifyCall from within InstCombine::visitCallInst
- Teach InstSimplify to fold [us]mul_with_overflow(X, undef) to 0.
llvm-svn: 237995
diff --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index ac94e75..465529a 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -1,6 +1,9 @@
; RUN: opt < %s -instsimplify -S | FileCheck %s
declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
+declare {i8, i1} @llvm.usub.with.overflow.i8(i8 %a, i8 %b)
+declare {i8, i1} @llvm.ssub.with.overflow.i8(i8 %a, i8 %b)
+declare {i8, i1} @llvm.umul.with.overflow.i8(i8 %a, i8 %b)
define i1 @test_uadd1() {
; CHECK-LABEL: @test_uadd1(
@@ -18,6 +21,27 @@
; CHECK-NEXT: ret i8 42
}
+define {i8, i1} @test_usub1(i8 %V) {
+; CHECK-LABEL: @test_usub1(
+ %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 %V)
+ ret {i8, i1} %x
+; CHECK-NEXT: ret { i8, i1 } zeroinitializer
+}
+
+define {i8, i1} @test_ssub1(i8 %V) {
+; CHECK-LABEL: @test_ssub1(
+ %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 %V)
+ ret {i8, i1} %x
+; CHECK-NEXT: ret { i8, i1 } zeroinitializer
+}
+
+define {i8, i1} @test_umul1(i8 %V) {
+; CHECK-LABEL: @test_umul1(
+ %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 0)
+ ret {i8, i1} %x
+; CHECK-NEXT: ret { i8, i1 } zeroinitializer
+}
+
declare i256 @llvm.cttz.i256(i256 %src, i1 %is_zero_undef)
define i256 @test_cttz() {