From: Simon Pilgrim Date: Tue, 20 Sep 2022 12:36:09 +0000 (+0100) Subject: [InstCombine] Add test coverage for D134172 / Issue #57635 X-Git-Tag: upstream/17.0.6~33038 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5a5d96394ebb1902f93bf91ab2a37b81a4cdc62;p=platform%2Fupstream%2Fllvm.git [InstCombine] Add test coverage for D134172 / Issue #57635 --- diff --git a/llvm/test/Transforms/InstCombine/icmp-add.ll b/llvm/test/Transforms/InstCombine/icmp-add.ll index 849946c..8fd23dd 100644 --- a/llvm/test/Transforms/InstCombine/icmp-add.ll +++ b/llvm/test/Transforms/InstCombine/icmp-add.ll @@ -1209,3 +1209,75 @@ define i1 @icmp_add_add_C_extra_use2(i32 %a, i32 %b) { %cmp = icmp ult i32 %add2, %a ret i1 %cmp } + +; PR57635 - fold ULT->ULE pre-decrement of a non-zero inputs + +define i1 @icmp_dec_assume_nonzero(i8 %x) { +; CHECK-LABEL: @icmp_dec_assume_nonzero( +; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[X:%.*]], 0 +; CHECK-NEXT: call void @llvm.assume(i1 [[Z]]) +; CHECK-NEXT: [[I:%.*]] = add i8 [[X]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[I]], 7 +; CHECK-NEXT: ret i1 [[C]] +; + %z = icmp ne i8 %x, 0 + call void @llvm.assume(i1 %z) + %i = add i8 %x, -1 + %c = icmp ult i8 %i, 7 + ret i1 %c +} + +define i1 @icmp_dec_sub_assume_nonzero(i8 %x) { +; CHECK-LABEL: @icmp_dec_sub_assume_nonzero( +; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[X:%.*]], 0 +; CHECK-NEXT: call void @llvm.assume(i1 [[Z]]) +; CHECK-NEXT: [[I:%.*]] = add i8 [[X]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[I]], 11 +; CHECK-NEXT: ret i1 [[C]] +; + %z = icmp ne i8 %x, 0 + call void @llvm.assume(i1 %z) + %i = sub i8 %x, 1 + %c = icmp ult i8 %i, 11 + ret i1 %c +} + +define i1 @icmp_dec_nonzero(i16 %x) { +; CHECK-LABEL: @icmp_dec_nonzero( +; CHECK-NEXT: [[O:%.*]] = or i16 [[X:%.*]], 4 +; CHECK-NEXT: [[I:%.*]] = add nsw i16 [[O]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ult i16 [[I]], 7 +; CHECK-NEXT: ret i1 [[C]] +; + %o = or i16 %x, 4 + %i = add i16 %o, -1 + %c = icmp ult i16 %i, 7 + ret i1 %c +} + +define <2 x i1> @icmp_dec_nonzero_vec(<2 x i32> %x) { +; CHECK-LABEL: @icmp_dec_nonzero_vec( +; CHECK-NEXT: [[O:%.*]] = or <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[I:%.*]] = add nsw <2 x i32> [[O]], +; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %o = or <2 x i32> %x, + %i = add <2 x i32> %o, + %c = icmp ult <2 x i32> %i, + ret <2 x i1> %c +} + +; Negative test +define i1 @icmp_dec_notnonzero(i8 %x) { +; CHECK-LABEL: @icmp_dec_notnonzero( +; CHECK-NEXT: [[I:%.*]] = add i8 [[X:%.*]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[I]], 11 +; CHECK-NEXT: ret i1 [[C]] +; + %i = add i8 %x, -1 + %c = icmp ult i8 %i, 11 + ret i1 %c +} + +declare void @llvm.assume(i1)