| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | |
| ; RUN: opt -S -passes=instcombine < %s | FileCheck %s | |
| define void @test_shl(i1 %x) { | |
| ; CHECK-LABEL: @test_shl( | |
| ; CHECK-NEXT: call void @sink(i8 0) | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %y = zext i1 %x to i8 | |
| %z = shl i8 64, %y | |
| %a = and i8 %z, 1 | |
| call void @sink(i8 %a) | |
| ret void | |
| } | |
| define void @test_lshr(i1 %x) { | |
| ; CHECK-LABEL: @test_lshr( | |
| ; CHECK-NEXT: call void @sink(i8 0) | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %y = zext i1 %x to i8 | |
| %z = lshr i8 64, %y | |
| %a = and i8 %z, 1 | |
| call void @sink(i8 %a) | |
| ret void | |
| } | |
| define void @test_ashr(i1 %x) { | |
| ; CHECK-LABEL: @test_ashr( | |
| ; CHECK-NEXT: call void @sink(i8 0) | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %y = zext i1 %x to i8 | |
| %z = ashr i8 -16, %y | |
| %a = and i8 %z, 3 | |
| call void @sink(i8 %a) | |
| ret void | |
| } | |
| define void @test_udiv(i8 %x) { | |
| ; CHECK-LABEL: @test_udiv( | |
| ; CHECK-NEXT: call void @sink(i8 0) | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %y = udiv i8 10, %x | |
| %z = and i8 %y, 64 | |
| call void @sink(i8 %z) | |
| ret void | |
| } | |
| define i8 @test_cond(i8 %x) { | |
| ; CHECK-LABEL: @test_cond( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp eq i8 %and, 0 | |
| br i1 %cmp, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_inv(i8 %x) { | |
| ; CHECK-LABEL: @test_cond_inv( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[AND]], 0 | |
| ; CHECK-NEXT: call void @use(i1 [[CMP]]) | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[IF:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp ne i8 %and, 0 | |
| call void @use(i1 %cmp) | |
| br i1 %cmp, label %exit, label %if | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_and(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_and( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP]], [[C:%.*]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp eq i8 %and, 0 | |
| %cond = and i1 %cmp, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_and_bothways(i8 %x) { | |
| ; CHECK-LABEL: @test_cond_and_bothways( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 91 | |
| ; CHECK-NEXT: [[CMP0:%.*]] = icmp ne i8 [[AND]], 24 | |
| ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i8 [[X]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP0]], [[CMP1]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: [[OR1:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR1]] | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; | |
| %and = and i8 %x, 91 | |
| %cmp0 = icmp ne i8 %and, 24 | |
| %cmp1 = icmp ne i8 %x, 0 | |
| %cond = and i1 %cmp0, %cmp1 | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_or_bothways(i8 %x) { | |
| ; CHECK-LABEL: @test_cond_or_bothways( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 91 | |
| ; CHECK-NEXT: [[CMP0:%.*]] = icmp eq i8 [[AND]], 24 | |
| ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[X]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = or i1 [[CMP0]], [[CMP1]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 91 | |
| %cmp0 = icmp eq i8 %and, 24 | |
| %cmp1 = icmp eq i8 %x, 0 | |
| %cond = or i1 %cmp0, %cmp1 | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_and_commuted(i8 %x, i1 %c1, i1 %c2) { | |
| ; CHECK-LABEL: @test_cond_and_commuted( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[C3:%.*]] = and i1 [[C1:%.*]], [[C2:%.*]] | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[C3]], [[CMP]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp eq i8 %and, 0 | |
| %c3 = and i1 %c1, %c2 | |
| %cond = and i1 %c3, %cmp | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_logical_and(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_logical_and( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i1 [[C:%.*]], i1 false | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp eq i8 %and, 0 | |
| %cond = select i1 %cmp, i1 %c, i1 false | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_or_invalid(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_or_invalid( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = or i1 [[CMP]], [[C:%.*]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: [[OR1:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR1]] | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp eq i8 %and, 0 | |
| %cond = or i1 %cmp, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_inv_or(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_inv_or( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = or i1 [[CMP]], [[C:%.*]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: [[OR1:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR1]] | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp ne i8 %and, 0 | |
| %cond = or i1 %cmp, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_inv_logical_or(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_inv_logical_or( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_NOT]], i1 [[C:%.*]], i1 false | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp ne i8 %and, 0 | |
| %cond = select i1 %cmp, i1 false, i1 %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_cond_inv_and_invalid(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_cond_inv_and_invalid( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[AND]], 0 | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP]], [[C:%.*]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: [[OR1:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR1]] | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp ne i8 %and, 0 | |
| %cond = and i1 %cmp, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define i32 @test_icmp_trunc1(i32 %x) { | |
| ; CHECK-LABEL: @test_icmp_trunc1( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[Y]], 7 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] | |
| ; CHECK: then: | |
| ; CHECK-NEXT: ret i32 7 | |
| ; CHECK: else: | |
| ; CHECK-NEXT: ret i32 0 | |
| ; | |
| entry: | |
| %y = trunc i32 %x to i16 | |
| %cmp = icmp eq i16 %y, 7 | |
| br i1 %cmp, label %then, label %else | |
| then: | |
| %z = and i32 %x, 15 | |
| ret i32 %z | |
| else: | |
| ret i32 0 | |
| } | |
| define i32 @test_icmp_trunc_assume(i32 %x) { | |
| ; CHECK-LABEL: @test_icmp_trunc_assume( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[Y:%.*]] = trunc i32 [[X:%.*]] to i16 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[Y]], 7 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: ret i32 7 | |
| ; | |
| entry: | |
| %y = trunc i32 %x to i16 | |
| %cmp = icmp eq i16 %y, 7 | |
| call void @llvm.assume(i1 %cmp) | |
| %z = and i32 %x, 15 | |
| ret i32 %z | |
| } | |
| define i64 @test_icmp_trunc2(i64 %x) { | |
| ; CHECK-LABEL: @test_icmp_trunc2( | |
| ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[X:%.*]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CONV]], 12 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[SEXT:%.*]] = and i64 [[X]], 2147483647 | |
| ; CHECK-NEXT: ret i64 [[SEXT]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i64 0 | |
| ; | |
| %conv = trunc i64 %x to i32 | |
| %cmp = icmp sgt i32 %conv, 12 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %sext = shl i64 %x, 32 | |
| %ret = ashr exact i64 %sext, 32 | |
| ret i64 %ret | |
| if.else: | |
| ret i64 0 | |
| } | |
| define i64 @test_icmp_trunc3(i64 %n) { | |
| ; CHECK-LABEL: @test_icmp_trunc3( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[N:%.*]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[CONV]], 96 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[RET:%.*]] = and i64 [[N]], 127 | |
| ; CHECK-NEXT: ret i64 [[RET]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i64 0 | |
| ; | |
| entry: | |
| %conv = trunc i64 %n to i32 | |
| %cmp = icmp ult i32 %conv, 96 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %ret = and i64 %n, 4294967295 | |
| ret i64 %ret | |
| if.else: | |
| ret i64 0 | |
| } | |
| define i8 @test_icmp_trunc4(i64 %n) { | |
| ; CHECK-LABEL: @test_icmp_trunc4( | |
| ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[N:%.*]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[CONV]], 10 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[CONV2:%.*]] = trunc i64 [[N]] to i8 | |
| ; CHECK-NEXT: [[ADD:%.*]] = or disjoint i8 [[CONV2]], 48 | |
| ; CHECK-NEXT: ret i8 [[ADD]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %conv = trunc i64 %n to i32 | |
| %cmp = icmp ult i32 %conv, 10 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %conv2 = trunc i64 %n to i8 | |
| %add = add i8 %conv2, 48 | |
| ret i8 %add | |
| if.else: | |
| ret i8 0 | |
| } | |
| define i64 @test_icmp_trunc5(i64 %n) { | |
| ; CHECK-LABEL: @test_icmp_trunc5( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[SHR:%.*]] = ashr i64 [[N:%.*]], 47 | |
| ; CHECK-NEXT: [[CONV1:%.*]] = trunc nsw i64 [[SHR]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[CONV1]], -13 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[SHR]], 15 | |
| ; CHECK-NEXT: [[NOT:%.*]] = xor i64 [[TMP0]], 15 | |
| ; CHECK-NEXT: ret i64 [[NOT]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i64 13 | |
| ; | |
| entry: | |
| %shr = ashr i64 %n, 47 | |
| %conv1 = trunc i64 %shr to i32 | |
| %cmp = icmp ugt i32 %conv1, -13 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %and = and i64 %shr, 4294967295 | |
| %not = xor i64 %and, 4294967295 | |
| ret i64 %not | |
| if.else: | |
| ret i64 13 | |
| } | |
| define i64 @test_icmp_trunc_nuw(i64 %a) { | |
| ; CHECK-LABEL: @test_icmp_trunc_nuw( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc nuw i64 [[A:%.*]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CAST]], 0 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i64 [[A]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i64 0 | |
| ; | |
| entry: | |
| %cast = trunc nuw i64 %a to i32 | |
| %cmp = icmp sgt i32 %cast, 0 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %b = and i64 %a, 2147483647 | |
| ret i64 %b | |
| if.else: | |
| ret i64 0 | |
| } | |
| define i64 @test_icmp_trunc_no_nuw(i64 %a) { | |
| ; CHECK-LABEL: @test_icmp_trunc_no_nuw( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc i64 [[A:%.*]] to i32 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CAST]], 0 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[B:%.*]] = and i64 [[A]], 2147483647 | |
| ; CHECK-NEXT: ret i64 [[B]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i64 0 | |
| ; | |
| entry: | |
| %cast = trunc i64 %a to i32 | |
| %cmp = icmp sgt i32 %cast, 0 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %b = and i64 %a, 2147483647 | |
| ret i64 %b | |
| if.else: | |
| ret i64 0 | |
| } | |
| define i1 @test_icmp_or_distjoint(i8 %n, i1 %other) { | |
| ; CHECK-LABEL: @test_icmp_or_distjoint( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or disjoint i8 [[N:%.*]], 16 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], -111 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i1 true | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i1 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_or = or disjoint i8 %n, 16 | |
| %cmp = icmp ugt i8 %n_or, 145 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = icmp slt i8 %n, 0 | |
| ret i1 %r | |
| if.else: | |
| ret i1 %other | |
| } | |
| define i1 @test_icmp_or_fail_missing_disjoint(i8 %n, i1 %other) { | |
| ; CHECK-LABEL: @test_icmp_or_fail_missing_disjoint( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], 16 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], -111 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[N]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i1 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_or = or i8 %n, 16 | |
| %cmp = icmp ugt i8 %n_or, 145 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = icmp slt i8 %n, 0 | |
| ret i1 %r | |
| if.else: | |
| ret i1 %other | |
| } | |
| define i8 @and_eq_bits_must_be_set(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @and_eq_bits_must_be_set( | |
| ; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| %xy = and i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 123 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %x, 1 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_or(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_or( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_OR]], 32 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_or = or i8 %n, %n2 | |
| %cmp = icmp ult i8 %n_or, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_or2(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_or2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], 14 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| entry: | |
| %n_or = or i8 %n, %n2 | |
| %cmp = icmp uge i8 %n_or, 15 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| ret i8 %other | |
| if.else: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_or_fail_bad_range(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_or_fail_bad_range( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_OR]], 33 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_or = or i8 %n, %n2 | |
| %cmp = icmp ule i8 %n_or, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_or_fail_bad_pred(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_or_fail_bad_pred( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], 32 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_or = or i8 %n, %n2 | |
| %cmp = icmp ugt i8 %n_or, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_and(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_and( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_AND:%.*]] = and i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_AND]], -33 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 32 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_and = and i8 %n, %n2 | |
| %cmp = icmp ugt i8 %n_and, 223 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_and2(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_and2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_AND:%.*]] = and i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_AND]], -31 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 32 | |
| ; | |
| entry: | |
| %n_and = and i8 %n, %n2 | |
| %cmp = icmp ule i8 %n_and, 224 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| ret i8 %other | |
| if.else: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_and_fail_bad_range(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_and_fail_bad_range( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_AND:%.*]] = and i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_AND]], -34 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_and = and i8 %n, %n2 | |
| %cmp = icmp uge i8 %n_and, 223 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_and_fail_bad_pred(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_and_fail_bad_pred( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_AND:%.*]] = and i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[N_AND]], 31 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_and = and i8 %n, %n2 | |
| %cmp = icmp sge i8 %n_and, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @and_eq_bits_must_be_set2(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @and_eq_bits_must_be_set2( | |
| ; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: ret i8 11 | |
| ; | |
| %xy = and i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 123 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %y, 11 | |
| ret i8 %r | |
| } | |
| define i8 @and_eq_bits_must_be_set2_partial_fail(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @and_eq_bits_must_be_set2_partial_fail( | |
| ; CHECK-NEXT: [[XY:%.*]] = and i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 123 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 111 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %xy = and i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 123 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %y, 111 | |
| ret i8 %r | |
| } | |
| define i8 @or_eq_bits_must_be_unset(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @or_eq_bits_must_be_unset( | |
| ; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %xy = or i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 124 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %x, 3 | |
| ret i8 %r | |
| } | |
| define i8 @or_eq_bits_must_be_unset2(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @or_eq_bits_must_be_unset2( | |
| ; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %xy = or i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 124 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %y, 1 | |
| ret i8 %r | |
| } | |
| define i8 @or_eq_bits_must_be_unset2_partial_fail(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @or_eq_bits_must_be_unset2_partial_fail( | |
| ; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[XY]], 124 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[Y]], 4 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %xy = or i8 %x, %y | |
| %cmp = icmp eq i8 %xy, 124 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %y, 7 | |
| ret i8 %r | |
| } | |
| define i8 @or_ne_bits_must_be_unset2_fail(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @or_ne_bits_must_be_unset2_fail( | |
| ; CHECK-NEXT: [[XY:%.*]] = or i8 [[X:%.*]], [[Y:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[XY]], 124 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 3 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %xy = or i8 %x, %y | |
| %cmp = icmp ne i8 %xy, 124 | |
| call void @llvm.assume(i1 %cmp) | |
| %r = and i8 %x, 3 | |
| ret i8 %r | |
| } | |
| declare void @use.i1(i1) | |
| declare void @use.i8(i8) | |
| declare void @use.2xi1(<2 x i1>) | |
| define i1 @extract_value_uadd(<2 x i8> %xx, <2 x i8> %yy) { | |
| ; CHECK-LABEL: @extract_value_uadd( | |
| ; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[Y0:%.*]] = and <2 x i8> [[YY:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw <2 x i8> [[X0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw <2 x i8> [[Y0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[ADD_UOV:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow.v2i8(<2 x i8> [[X]], <2 x i8> [[Y]]) | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.2xi1(<2 x i1> [[UOV]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %x0 = and <2 x i8> %xx, <i8 63, i8 255> | |
| %y0 = and <2 x i8> %yy, <i8 63, i8 255> | |
| %x = add nuw <2 x i8> %x0, <i8 1, i8 0> | |
| %y = add nuw <2 x i8> %y0, <i8 1, i8 0> | |
| %add_uov = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow(<2 x i8> %x, <2 x i8> %y) | |
| %add = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 0 | |
| %uov = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 1 | |
| call void @use.2xi1(<2 x i1> %uov) | |
| %add_ele = extractelement <2 x i8> %add, i32 0 | |
| %r = icmp eq i8 %add_ele, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_uadd2(<2 x i8> %xx, <2 x i8> %yy) { | |
| ; CHECK-LABEL: @extract_value_uadd2( | |
| ; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], <i8 -1, i8 63> | |
| ; CHECK-NEXT: [[Y0:%.*]] = and <2 x i8> [[YY:%.*]], <i8 -1, i8 63> | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw <2 x i8> [[X0]], <i8 0, i8 1> | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw <2 x i8> [[Y0]], <i8 0, i8 1> | |
| ; CHECK-NEXT: [[ADD_UOV:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow.v2i8(<2 x i8> [[X]], <2 x i8> [[Y]]) | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.2xi1(<2 x i1> [[UOV]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %x0 = and <2 x i8> %xx, <i8 255, i8 63> | |
| %y0 = and <2 x i8> %yy, <i8 255, i8 63> | |
| %x = add nuw <2 x i8> %x0, <i8 0, i8 1> | |
| %y = add nuw <2 x i8> %y0, <i8 0, i8 1> | |
| %add_uov = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow(<2 x i8> %x, <2 x i8> %y) | |
| %add = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 0 | |
| %uov = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 1 | |
| call void @use.2xi1(<2 x i1> %uov) | |
| %add_ele = extractelement <2 x i8> %add, i32 1 | |
| %r = icmp eq i8 %add_ele, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_uadd_fail(<2 x i8> %xx, <2 x i8> %yy) { | |
| ; CHECK-LABEL: @extract_value_uadd_fail( | |
| ; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[Y0:%.*]] = and <2 x i8> [[YY:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw <2 x i8> [[X0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw <2 x i8> [[Y0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[ADD_UOV:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow.v2i8(<2 x i8> [[X]], <2 x i8> [[Y]]) | |
| ; CHECK-NEXT: [[ADD:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.2xi1(<2 x i1> [[UOV]]) | |
| ; CHECK-NEXT: [[ADD_ELE:%.*]] = extractelement <2 x i8> [[ADD]], i64 1 | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ADD_ELE]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x0 = and <2 x i8> %xx, <i8 63, i8 255> | |
| %y0 = and <2 x i8> %yy, <i8 63, i8 255> | |
| %x = add nuw <2 x i8> %x0, <i8 1, i8 0> | |
| %y = add nuw <2 x i8> %y0, <i8 1, i8 0> | |
| %add_uov = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow(<2 x i8> %x, <2 x i8> %y) | |
| %add = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 0 | |
| %uov = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 1 | |
| call void @use.2xi1(<2 x i1> %uov) | |
| %add_ele = extractelement <2 x i8> %add, i32 1 | |
| %r = icmp eq i8 %add_ele, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_uadd_fail2(<2 x i8> %xx, <2 x i8> %yy, i32 %idx) { | |
| ; CHECK-LABEL: @extract_value_uadd_fail2( | |
| ; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[Y0:%.*]] = and <2 x i8> [[YY:%.*]], <i8 63, i8 -1> | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw <2 x i8> [[X0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw <2 x i8> [[Y0]], <i8 1, i8 0> | |
| ; CHECK-NEXT: [[ADD_UOV:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow.v2i8(<2 x i8> [[X]], <2 x i8> [[Y]]) | |
| ; CHECK-NEXT: [[ADD:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.2xi1(<2 x i1> [[UOV]]) | |
| ; CHECK-NEXT: [[ADD_ELE:%.*]] = extractelement <2 x i8> [[ADD]], i32 [[IDX:%.*]] | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ADD_ELE]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x0 = and <2 x i8> %xx, <i8 63, i8 255> | |
| %y0 = and <2 x i8> %yy, <i8 63, i8 255> | |
| %x = add nuw <2 x i8> %x0, <i8 1, i8 0> | |
| %y = add nuw <2 x i8> %y0, <i8 1, i8 0> | |
| %add_uov = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow(<2 x i8> %x, <2 x i8> %y) | |
| %add = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 0 | |
| %uov = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 1 | |
| call void @use.2xi1(<2 x i1> %uov) | |
| %add_ele = extractelement <2 x i8> %add, i32 %idx | |
| %r = icmp eq i8 %add_ele, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_uadd_fail3(<2 x i8> %xx, <2 x i8> %yy) { | |
| ; CHECK-LABEL: @extract_value_uadd_fail3( | |
| ; CHECK-NEXT: [[X0:%.*]] = and <2 x i8> [[XX:%.*]], splat (i8 127) | |
| ; CHECK-NEXT: [[Y0:%.*]] = and <2 x i8> [[YY:%.*]], splat (i8 127) | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw <2 x i8> [[X0]], splat (i8 1) | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw <2 x i8> [[Y0]], splat (i8 1) | |
| ; CHECK-NEXT: [[ADD_UOV:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow.v2i8(<2 x i8> [[X]], <2 x i8> [[Y]]) | |
| ; CHECK-NEXT: [[ADD:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[ADD_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.2xi1(<2 x i1> [[UOV]]) | |
| ; CHECK-NEXT: [[ADD_ELE:%.*]] = extractelement <2 x i8> [[ADD]], i64 0 | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ADD_ELE]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x0 = and <2 x i8> %xx, <i8 127, i8 127> | |
| %y0 = and <2 x i8> %yy, <i8 127, i8 127> | |
| %x = add nuw <2 x i8> %x0, <i8 1, i8 1> | |
| %y = add nuw <2 x i8> %y0, <i8 1, i8 1> | |
| %add_uov = call { <2 x i8>, <2 x i1> } @llvm.uadd.with.overflow(<2 x i8> %x, <2 x i8> %y) | |
| %add = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 0 | |
| %uov = extractvalue { <2 x i8>, <2 x i1> } %add_uov, 1 | |
| call void @use.2xi1(<2 x i1> %uov) | |
| %add_ele = extractelement <2 x i8> %add, i32 0 | |
| %r = icmp eq i8 %add_ele, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_sadd(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_sadd( | |
| ; CHECK-NEXT: [[X:%.*]] = add nuw i8 [[XX:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[X_LEMMA:%.*]] = icmp sgt i8 [[X]], -1 | |
| ; CHECK-NEXT: [[Y_LEMMA:%.*]] = icmp sgt i8 [[Y]], -1 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[X_LEMMA]]) | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_LEMMA]]) | |
| ; CHECK-NEXT: [[ADD_SOV:%.*]] = call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[ADD_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %x = add nuw i8 %xx, 1 | |
| %y = add nuw i8 %yy, 1 | |
| %x_lemma = icmp ult i8 %x, 128 | |
| %y_lemma = icmp ult i8 %y, 128 | |
| call void @llvm.assume(i1 %x_lemma) | |
| call void @llvm.assume(i1 %y_lemma) | |
| %add_sov = call { i8, i1 } @llvm.sadd.with.overflow(i8 %x, i8 %y) | |
| %add = extractvalue { i8, i1 } %add_sov, 0 | |
| %sov = extractvalue { i8, i1 } %add_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| %r = icmp eq i8 %add, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_sadd_fail(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_sadd_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = add i8 [[XX:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[ADD_SOV:%.*]] = call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[ADD:%.*]] = extractvalue { i8, i1 } [[ADD_SOV]], 0 | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[ADD_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ADD]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x = add i8 %xx, 1 | |
| %y = add i8 %yy, 1 | |
| %add_sov = call { i8, i1 } @llvm.sadd.with.overflow(i8 %x, i8 %y) | |
| %add = extractvalue { i8, i1 } %add_sov, 0 | |
| %sov = extractvalue { i8, i1 } %add_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| %r = icmp eq i8 %add, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_usub(i8 %x, i8 %zz) { | |
| ; CHECK-LABEL: @extract_value_usub( | |
| ; CHECK-NEXT: [[Z:%.*]] = add nuw i8 [[ZZ:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add i8 [[X:%.*]], [[Z]] | |
| ; CHECK-NEXT: [[SUB_UOV:%.*]] = call { i8, i1 } @llvm.usub.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[SUB:%.*]] = extractvalue { i8, i1 } [[SUB_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { i8, i1 } [[SUB_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[UOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[SUB]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %z = add nuw i8 %zz, 1 | |
| %y = add i8 %x, %z | |
| %sub_uov = call { i8, i1 } @llvm.usub.with.overflow(i8 %x, i8 %y) | |
| %sub = extractvalue { i8, i1 } %sub_uov, 0 | |
| %uov = extractvalue { i8, i1 } %sub_uov, 1 | |
| call void @use.i1(i1 %uov) | |
| call void @use.i8(i8 %sub) | |
| %r = icmp eq i8 %sub, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_usub_fail(i8 %x, i8 %z) { | |
| ; CHECK-LABEL: @extract_value_usub_fail( | |
| ; CHECK-NEXT: [[Y:%.*]] = add i8 [[X:%.*]], [[Z:%.*]] | |
| ; CHECK-NEXT: [[SUB_UOV:%.*]] = call { i8, i1 } @llvm.usub.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[SUB:%.*]] = extractvalue { i8, i1 } [[SUB_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { i8, i1 } [[SUB_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[UOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[SUB]]) | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[SUB]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %y = add i8 %x, %z | |
| %sub_uov = call { i8, i1 } @llvm.usub.with.overflow(i8 %x, i8 %y) | |
| %sub = extractvalue { i8, i1 } %sub_uov, 0 | |
| %uov = extractvalue { i8, i1 } %sub_uov, 1 | |
| call void @use.i1(i1 %uov) | |
| call void @use.i8(i8 %sub) | |
| %r = icmp eq i8 %sub, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_ssub(i8 %x, i8 %zz) { | |
| ; CHECK-LABEL: @extract_value_ssub( | |
| ; CHECK-NEXT: [[Z:%.*]] = add nuw i8 [[ZZ:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add i8 [[X:%.*]], [[Z]] | |
| ; CHECK-NEXT: [[SUB_SOV:%.*]] = call { i8, i1 } @llvm.ssub.with.overflow.i8(i8 [[Y]], i8 [[X]]) | |
| ; CHECK-NEXT: [[SUB:%.*]] = extractvalue { i8, i1 } [[SUB_SOV]], 0 | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[SUB_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[SUB]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %z = add nuw i8 %zz, 1 | |
| %y = add i8 %x, %z | |
| %sub_sov = call { i8, i1 } @llvm.ssub.with.overflow(i8 %y, i8 %x) | |
| %sub = extractvalue { i8, i1 } %sub_sov, 0 | |
| %sov = extractvalue { i8, i1 } %sub_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| call void @use.i8(i8 %sub) | |
| %r = icmp eq i8 %sub, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_ssub_fail(i8 %x) { | |
| ; CHECK-LABEL: @extract_value_ssub_fail( | |
| ; CHECK-NEXT: [[SUB_SOV:%.*]] = call { i8, i1 } @llvm.ssub.with.overflow.i8(i8 10, i8 [[X:%.*]]) | |
| ; CHECK-NEXT: [[SUB:%.*]] = extractvalue { i8, i1 } [[SUB_SOV]], 0 | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[SUB_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[SUB]]) | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[SUB]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %sub_sov = call { i8, i1 } @llvm.ssub.with.overflow(i8 10, i8 %x) | |
| %sub = extractvalue { i8, i1 } %sub_sov, 0 | |
| %sov = extractvalue { i8, i1 } %sub_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| call void @use.i8(i8 %sub) | |
| %r = icmp eq i8 %sub, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_umul(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_umul( | |
| ; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[MUL_UOV:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[MUL:%.*]] = extractvalue { i8, i1 } [[MUL_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { i8, i1 } [[MUL_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[UOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[MUL]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %x = or i8 %xx, 1 | |
| %y = add nuw i8 %yy, 1 | |
| %mul_uov = call { i8, i1 } @llvm.umul.with.overflow(i8 %x, i8 %y) | |
| %mul = extractvalue { i8, i1 } %mul_uov, 0 | |
| %uov = extractvalue { i8, i1 } %mul_uov, 1 | |
| call void @use.i1(i1 %uov) | |
| call void @use.i8(i8 %mul) | |
| %r = icmp eq i8 %mul, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_umul_fail(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_umul_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 2 | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[MUL_UOV:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X]], i8 [[Y]]) | |
| ; CHECK-NEXT: [[MUL:%.*]] = extractvalue { i8, i1 } [[MUL_UOV]], 0 | |
| ; CHECK-NEXT: [[UOV:%.*]] = extractvalue { i8, i1 } [[MUL_UOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[UOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[MUL]]) | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[MUL]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x = or i8 %xx, 2 | |
| %y = add nuw i8 %yy, 1 | |
| %mul_uov = call { i8, i1 } @llvm.umul.with.overflow(i8 %x, i8 %y) | |
| %mul = extractvalue { i8, i1 } %mul_uov, 0 | |
| %uov = extractvalue { i8, i1 } %mul_uov, 1 | |
| call void @use.i1(i1 %uov) | |
| call void @use.i8(i8 %mul) | |
| %r = icmp eq i8 %mul, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_smul(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_smul( | |
| ; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add nuw i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[MUL_SOV:%.*]] = call { i8, i1 } @llvm.smul.with.overflow.i8(i8 [[Y]], i8 [[X]]) | |
| ; CHECK-NEXT: [[MUL:%.*]] = extractvalue { i8, i1 } [[MUL_SOV]], 0 | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[MUL_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[MUL]]) | |
| ; CHECK-NEXT: ret i1 false | |
| ; | |
| %x = or i8 %xx, 1 | |
| %y = add nuw i8 %yy, 1 | |
| %mul_sov = call { i8, i1 } @llvm.smul.with.overflow(i8 %y, i8 %x) | |
| %mul = extractvalue { i8, i1 } %mul_sov, 0 | |
| %sov = extractvalue { i8, i1 } %mul_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| call void @use.i8(i8 %mul) | |
| %r = icmp eq i8 %mul, 0 | |
| ret i1 %r | |
| } | |
| define i1 @extract_value_smul_fail(i8 %xx, i8 %yy) { | |
| ; CHECK-LABEL: @extract_value_smul_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 1 | |
| ; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], 1 | |
| ; CHECK-NEXT: [[MUL_SOV:%.*]] = call { i8, i1 } @llvm.smul.with.overflow.i8(i8 [[Y]], i8 [[X]]) | |
| ; CHECK-NEXT: [[MUL:%.*]] = extractvalue { i8, i1 } [[MUL_SOV]], 0 | |
| ; CHECK-NEXT: [[SOV:%.*]] = extractvalue { i8, i1 } [[MUL_SOV]], 1 | |
| ; CHECK-NEXT: call void @use.i1(i1 [[SOV]]) | |
| ; CHECK-NEXT: call void @use.i8(i8 [[MUL]]) | |
| ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[MUL]], 0 | |
| ; CHECK-NEXT: ret i1 [[R]] | |
| ; | |
| %x = or i8 %xx, 1 | |
| %y = add i8 %yy, 1 | |
| %mul_sov = call { i8, i1 } @llvm.smul.with.overflow(i8 %y, i8 %x) | |
| %mul = extractvalue { i8, i1 } %mul_sov, 0 | |
| %sov = extractvalue { i8, i1 } %mul_sov, 1 | |
| call void @use.i1(i1 %sov) | |
| call void @use.i8(i8 %mul) | |
| %r = icmp eq i8 %mul, 0 | |
| ret i1 %r | |
| } | |
| define i8 @known_self_mul_bit_0_set(i8 noundef %x) { | |
| ; CHECK-LABEL: @known_self_mul_bit_0_set( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %bit_0_set = or i8 %x, 1 | |
| %self_mul = mul i8 %bit_0_set, %bit_0_set | |
| %r = and i8 %self_mul, 4 | |
| ret i8 %r | |
| } | |
| define i8 @known_self_mul_bit_0_unset(i8 noundef %x) { | |
| ; CHECK-LABEL: @known_self_mul_bit_0_unset( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %bit_0_unset = and i8 %x, -2 | |
| %self_mul = mul i8 %bit_0_unset, %bit_0_unset | |
| %r = and i8 %self_mul, 8 | |
| ret i8 %r | |
| } | |
| define i8 @known_self_mul_bit_1_set_bit_0_unset(i8 noundef %x) { | |
| ; CHECK-LABEL: @known_self_mul_bit_1_set_bit_0_unset( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %lower_2_unset = and i8 %x, -4 | |
| %bit_1_set_bit_0_unset = or disjoint i8 %lower_2_unset, 2 | |
| %self_mul = mul i8 %bit_1_set_bit_0_unset, %bit_1_set_bit_0_unset | |
| %r = and i8 %self_mul, 24 | |
| ret i8 %r | |
| } | |
| define i4 @known_self_mul_bit_1_set_bit_0_unset_i4(i4 noundef %x) { | |
| ; CHECK-LABEL: @known_self_mul_bit_1_set_bit_0_unset_i4( | |
| ; CHECK-NEXT: ret i4 0 | |
| ; | |
| %lower_2_unset = and i4 %x, -4 | |
| %bit_1_set_bit_0_unset = or disjoint i4 %lower_2_unset, 2 | |
| %self_mul = mul i4 %bit_1_set_bit_0_unset, %bit_1_set_bit_0_unset | |
| %r = and i4 %self_mul, 24 | |
| ret i4 %r | |
| } | |
| define i8 @known_reduce_or(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_or( | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.or(<2 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_or_fail(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_or_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3> | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.or.v2i8(<2 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 4 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.or(<2 x i8> %x) | |
| %r = and i8 %v, 4 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_and(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_and( | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.and(<2 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_and_fail(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_and_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3> | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.and.v2i8(<2 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.and(<2 x i8> %x) | |
| %r = and i8 %v, 2 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_even(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_even( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_even2(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_even2( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %x = and <2 x i8> %xx, <i8 15, i8 15> | |
| %v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x) | |
| %r = and i8 %v, 16 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_even_fail(<2 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_even_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3> | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %x = or <2 x i8> %xx, <i8 5, i8 3> | |
| %v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x) | |
| %r = and i8 %v, 2 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_odd(<3 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_odd( | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| %x = or <3 x i8> %xx, <i8 5, i8 3, i8 9> | |
| %v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_odd2(<3 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_odd2( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %x = and <3 x i8> %xx, <i8 15, i8 15, i8 31> | |
| %v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x) | |
| %r = and i8 %v, 32 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_odd2_fail(<3 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_odd2_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 15, i8 15, i8 31> | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 16 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %x = and <3 x i8> %xx, <i8 15, i8 15, i8 31> | |
| %v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x) | |
| %r = and i8 %v, 16 | |
| ret i8 %r | |
| } | |
| define i8 @known_reduce_xor_odd_fail(<3 x i8> %xx) { | |
| ; CHECK-LABEL: @known_reduce_xor_odd_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <3 x i8> [[XX:%.*]], <i8 5, i8 3, i8 9> | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %x = or <3 x i8> %xx, <i8 5, i8 3, i8 9> | |
| %v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x) | |
| %r = and i8 %v, 2 | |
| ret i8 %r | |
| } | |
| define i8 @nonzero_reduce_xor_vscale_even(<vscale x 2 x i8> %xx) { | |
| ; CHECK-LABEL: @nonzero_reduce_xor_vscale_even( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %one = insertelement <vscale x 2 x i8> poison, i8 1, i64 0 | |
| %ones = shufflevector <vscale x 2 x i8> %one, <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer | |
| %x = or <vscale x 2 x i8> %xx, %ones | |
| %v = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @nonzero_reduce_xor_vscale_odd_fail(<vscale x 3 x i8> %xx) { | |
| ; CHECK-LABEL: @nonzero_reduce_xor_vscale_odd_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <vscale x 3 x i8> [[XX:%.*]], splat (i8 1) | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %one = insertelement <vscale x 3 x i8> poison, i8 1, i64 0 | |
| %ones = shufflevector <vscale x 3 x i8> %one, <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer | |
| %x = or <vscale x 3 x i8> %xx, %ones | |
| %v = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> %x) | |
| %r = and i8 %v, 1 | |
| ret i8 %r | |
| } | |
| define i8 @nonzero_reduce_xor_vscale_even_fail(<vscale x 2 x i8> %xx) { | |
| ; CHECK-LABEL: @nonzero_reduce_xor_vscale_even_fail( | |
| ; CHECK-NEXT: [[X:%.*]] = or <vscale x 2 x i8> [[XX:%.*]], splat (i8 1) | |
| ; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> [[X]]) | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 2 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| %one = insertelement <vscale x 2 x i8> poison, i8 1, i64 0 | |
| %ones = shufflevector <vscale x 2 x i8> %one, <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer | |
| %x = or <vscale x 2 x i8> %xx, %ones | |
| %v = call i8 @llvm.vector.reduce.xor.nxv2i8(<vscale x 2 x i8> %x) | |
| %r = and i8 %v, 2 | |
| ret i8 %r | |
| } | |
| define i8 @nonzero_reduce_xor_vscale_odd(<vscale x 3 x i8> %xx) { | |
| ; CHECK-LABEL: @nonzero_reduce_xor_vscale_odd( | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %one = insertelement <vscale x 3 x i8> poison, i8 1, i64 0 | |
| %ones = shufflevector <vscale x 3 x i8> %one, <vscale x 3 x i8> poison, <vscale x 3 x i32> zeroinitializer | |
| %x = and <vscale x 3 x i8> %xx, %ones | |
| %v = call i8 @llvm.vector.reduce.xor.nxv3i8(<vscale x 3 x i8> %x) | |
| %r = and i8 %v, 2 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_add(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_add( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_ADD:%.*]] = add nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_ADD]], 32 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_add = add nuw i8 %n, %n2 | |
| %cmp = icmp ult i8 %n_add, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_add_fail_nsw(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_add_fail_nsw( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_ADD:%.*]] = add nsw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_ADD]], 32 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_add = add nsw i8 %n, %n2 | |
| %cmp = icmp ult i8 %n_add, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_add2(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_add2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_ADD:%.*]] = add nuw nsw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_ADD]], 14 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| entry: | |
| %n_add = add nsw nuw i8 %n, %n2 | |
| %cmp = icmp uge i8 %n_add, 15 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| ret i8 %other | |
| if.else: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_add_fail_bad_range(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_add_fail_bad_range( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_ADD:%.*]] = add nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_ADD]], 33 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_add = add nuw i8 %n, %n2 | |
| %cmp = icmp ule i8 %n_add, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_add_fail_bad_pred(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_add_fail_bad_pred( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_ADD:%.*]] = add nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_ADD]], 32 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_add = add nuw i8 %n, %n2 | |
| %cmp = icmp ugt i8 %n_add, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_sub(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_SUB]], -33 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 32 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_sub = sub nuw i8 %n, %n2 | |
| %cmp = icmp ugt i8 %n_sub, 223 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_sub_fail_wrong_arg(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub_fail_wrong_arg( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_SUB]], -33 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N2]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_sub = sub nuw i8 %n, %n2 | |
| %cmp = icmp ugt i8 %n_sub, 223 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n2, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_sub2(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_SUB]], -31 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 32 | |
| ; | |
| entry: | |
| %n_sub = sub nuw i8 %n, %n2 | |
| %cmp = icmp ule i8 %n_sub, 224 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| ret i8 %other | |
| if.else: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_sub2_fail_nsw(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub2_fail_nsw( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nsw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[N_SUB]], -31 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; | |
| entry: | |
| %n_sub = sub nsw i8 %n, %n2 | |
| %cmp = icmp ule i8 %n_sub, 224 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| ret i8 %other | |
| if.else: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| } | |
| define i8 @test_icmp_sub_fail_bad_range(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub_fail_bad_range( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_SUB]], -34 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_sub = sub nuw i8 %n, %n2 | |
| %cmp = icmp uge i8 %n_sub, 223 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @test_icmp_sub_fail_bad_pred(i8 %n, i8 %n2, i8 %other) { | |
| ; CHECK-LABEL: @test_icmp_sub_fail_bad_pred( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[N_SUB:%.*]] = sub nuw i8 [[N:%.*]], [[N2:%.*]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[N_SUB]], 31 | |
| ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[R:%.*]] = and i8 [[N]], 32 | |
| ; CHECK-NEXT: ret i8 [[R]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 [[OTHER:%.*]] | |
| ; | |
| entry: | |
| %n_sub = sub nuw i8 %n, %n2 | |
| %cmp = icmp sge i8 %n_sub, 32 | |
| br i1 %cmp, label %if.then, label %if.else | |
| if.then: | |
| %r = and i8 %n, 32 | |
| ret i8 %r | |
| if.else: | |
| ret i8 %other | |
| } | |
| define i8 @simplifydemanded_context(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @simplifydemanded_context( | |
| ; CHECK-NEXT: call void @dummy() | |
| ; CHECK-NEXT: [[X_LOBITS:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[PRECOND:%.*]] = icmp eq i8 [[X_LOBITS]], 0 | |
| ; CHECK-NEXT: call void @llvm.assume(i1 [[PRECOND]]) | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| %and1 = and i8 %x, 1 | |
| call void @dummy() ; may unwind | |
| %x.lobits = and i8 %x, 3 | |
| %precond = icmp eq i8 %x.lobits, 0 | |
| call void @llvm.assume(i1 %precond) | |
| %and2 = and i8 %and1, %y | |
| ret i8 %and2 | |
| } | |
| define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { | |
| ; CHECK-LABEL: @pr97330( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: br i1 [[C:%.*]], label [[EXIT:%.*]], label [[IF:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: unreachable | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[V:%.*]] = load i64, ptr [[P1:%.*]], align 8 | |
| ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[V]] to i16 | |
| ; CHECK-NEXT: ret i16 [[CONV]] | |
| ; | |
| entry: | |
| %v = load i64, ptr %p1, align 8 | |
| %conv = trunc i64 %v to i16 | |
| br i1 %c, label %exit, label %if | |
| if: | |
| %cmp = icmp ne i16 %conv, 1 | |
| %conv2 = zext i1 %cmp to i32 | |
| store i32 %conv2, ptr %p2, align 4 | |
| %cmp2 = icmp eq i64 %v, 1 | |
| call void @llvm.assume(i1 %cmp2) | |
| unreachable | |
| exit: | |
| ret i16 %conv | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_const(i8 %x) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_const( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %mul = mul nuw nsw i8 %x, 3 | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_const_missing_nuw(i8 %x) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_const_missing_nuw( | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1 | |
| ; CHECK-NEXT: ret i1 [[CMP]] | |
| ; | |
| %mul = mul nsw i8 %x, 3 | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_const_missing_nsw(i8 %x) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_const_missing_nsw( | |
| ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[MUL]], -1 | |
| ; CHECK-NEXT: ret i1 [[CMP]] | |
| ; | |
| %mul = mul nuw i8 %x, 3 | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_can_be_one(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_can_be_one( | |
| ; CHECK-NEXT: [[Y_NNEG:%.*]] = and i8 [[Y:%.*]], 127 | |
| ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i8 [[X:%.*]], [[Y_NNEG]] | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[MUL]], -1 | |
| ; CHECK-NEXT: ret i1 [[CMP]] | |
| ; | |
| %y.nneg = and i8 %y, 127 | |
| %mul = mul nuw nsw i8 %x, %y.nneg | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_cant_be_one(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_cant_be_one( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %y.nneg = and i8 %y, 127 | |
| %y.nneg.not.one = or i8 %y.nneg, 2 | |
| %mul = mul nuw nsw i8 %x, %y.nneg.not.one | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i1 @mul_nuw_nsw_nonneg_cant_be_one_commuted(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @mul_nuw_nsw_nonneg_cant_be_one_commuted( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %y.nneg = and i8 %y, 127 | |
| %y.nneg.not.one = or i8 %y.nneg, 2 | |
| %mul = mul nuw nsw i8 %y.nneg.not.one, %x | |
| %cmp = icmp sgt i8 %mul, -1 | |
| ret i1 %cmp | |
| } | |
| define i8 @test_trunc_and_1(i8 %a) { | |
| ; CHECK-LABEL: @test_trunc_and_1( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 1 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; | |
| entry: | |
| %cast = trunc i8 %a to i1 | |
| br i1 %cast, label %if.then, label %if.else | |
| if.then: | |
| %b = and i8 %a, 1 | |
| ret i8 %b | |
| if.else: | |
| %c = and i8 %a, 1 | |
| ret i8 %c | |
| } | |
| define i8 @test_not_trunc_and_1(i8 %a) { | |
| ; CHECK-LABEL: @test_not_trunc_and_1( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| entry: | |
| %cast = trunc i8 %a to i1 | |
| %not = xor i1 %cast, true | |
| br i1 %not, label %if.then, label %if.else | |
| if.then: | |
| %b = and i8 %a, 1 | |
| ret i8 %b | |
| if.else: | |
| %c = and i8 %a, 1 | |
| ret i8 %c | |
| } | |
| define i8 @neg_test_trunc_or_2(i8 %a) { | |
| ; CHECK-LABEL: @neg_test_trunc_or_2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: [[B:%.*]] = or i8 [[A]], 2 | |
| ; CHECK-NEXT: ret i8 [[B]] | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: [[C:%.*]] = or i8 [[A]], 2 | |
| ; CHECK-NEXT: ret i8 [[C]] | |
| ; | |
| entry: | |
| %cast = trunc i8 %a to i1 | |
| br i1 %cast, label %if.then, label %if.else | |
| if.then: | |
| %b = or i8 %a, 2 | |
| ret i8 %b | |
| if.else: | |
| %c = or i8 %a, 2 | |
| ret i8 %c | |
| } | |
| define i8 @test_trunc_nuw_and_1(i8 %a) { | |
| ; CHECK-LABEL: @test_trunc_nuw_and_1( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc nuw i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| entry: | |
| %cast = trunc nuw i8 %a to i1 | |
| br i1 %cast, label %if.else, label %if.then | |
| if.then: | |
| %b = and i8 %a, 1 | |
| ret i8 %b | |
| if.else: | |
| %c = and i8 %a, 1 | |
| ret i8 %c | |
| } | |
| define i8 @test_trunc_nuw_or_2(i8 %a) { | |
| ; CHECK-LABEL: @test_trunc_nuw_or_2( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc nuw i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 2 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 3 | |
| ; | |
| entry: | |
| %cast = trunc nuw i8 %a to i1 | |
| br i1 %cast, label %if.else, label %if.then | |
| if.then: | |
| %b = or i8 %a, 2 | |
| ret i8 %b | |
| if.else: | |
| %c = or i8 %a, 2 | |
| ret i8 %c | |
| } | |
| define i8 @test_not_trunc_nuw_and_1(i8 %a) { | |
| ; CHECK-LABEL: @test_not_trunc_nuw_and_1( | |
| ; CHECK-NEXT: entry: | |
| ; CHECK-NEXT: [[CAST:%.*]] = trunc nuw i8 [[A:%.*]] to i1 | |
| ; CHECK-NEXT: br i1 [[CAST]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]] | |
| ; CHECK: if.then: | |
| ; CHECK-NEXT: ret i8 0 | |
| ; CHECK: if.else: | |
| ; CHECK-NEXT: ret i8 1 | |
| ; | |
| entry: | |
| %cast = trunc nuw i8 %a to i1 | |
| %not = xor i1 %cast, true | |
| br i1 %not, label %if.then, label %if.else | |
| if.then: | |
| %b = and i8 %a, 1 | |
| ret i8 %b | |
| if.else: | |
| %c = and i8 %a, 1 | |
| ret i8 %c | |
| } | |
| define i8 @test_trunc_cond_and(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_trunc_cond_and( | |
| ; CHECK-NEXT: [[CMP:%.*]] = trunc i8 [[X:%.*]] to i1 | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[C:%.*]], [[CMP]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -1 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -2 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %cmp = trunc i8 %x to i1 | |
| %cond = and i1 %cmp, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -2 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -2 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_not_trunc_cond_and(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_not_trunc_cond_and( | |
| ; CHECK-NEXT: [[CMP:%.*]] = trunc i8 [[X:%.*]] to i1 | |
| ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CMP]], true | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[C:%.*]], [[NOT]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -2 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -2 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %cmp = trunc i8 %x to i1 | |
| %not = xor i1 %cmp, true | |
| %cond = and i1 %not, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -2 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -2 | |
| ret i8 %or2 | |
| } | |
| define i8 @test_inv_cond_and(i8 %x, i1 %c) { | |
| ; CHECK-LABEL: @test_inv_cond_and( | |
| ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 3 | |
| ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[AND]], 0 | |
| ; CHECK-NEXT: call void @use(i1 [[CMP]]) | |
| ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CMP]], true | |
| ; CHECK-NEXT: [[COND:%.*]] = and i1 [[C:%.*]], [[NOT]] | |
| ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]] | |
| ; CHECK: if: | |
| ; CHECK-NEXT: ret i8 -4 | |
| ; CHECK: exit: | |
| ; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4 | |
| ; CHECK-NEXT: ret i8 [[OR2]] | |
| ; | |
| %and = and i8 %x, 3 | |
| %cmp = icmp ne i8 %and, 0 | |
| call void @use(i1 %cmp) | |
| %not = xor i1 %cmp, true | |
| %cond = and i1 %not, %c | |
| br i1 %cond, label %if, label %exit | |
| if: | |
| %or1 = or i8 %x, -4 | |
| ret i8 %or1 | |
| exit: | |
| %or2 = or i8 %x, -4 | |
| ret i8 %or2 | |
| } | |
| define <vscale x 4 x i32> @scalable_add_to_disjoint_or(i8 %x, <vscale x 4 x i32> range(i32 0, 256) %rhs) { | |
| ; CHECK-LABEL: @scalable_add_to_disjoint_or( | |
| ; CHECK-NEXT: [[EXTX:%.*]] = zext i8 [[X:%.*]] to i32 | |
| ; CHECK-NEXT: [[SHIFT:%.*]] = shl nuw nsw i32 [[EXTX]], 8 | |
| ; CHECK-NEXT: [[INSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[SHIFT]], i64 0 | |
| ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[INSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer | |
| ; CHECK-NEXT: [[ADD:%.*]] = or disjoint <vscale x 4 x i32> [[SPLAT]], [[RHS:%.*]] | |
| ; CHECK-NEXT: ret <vscale x 4 x i32> [[ADD]] | |
| ; | |
| %extx = zext i8 %x to i32 | |
| %shift = shl nuw nsw i32 %extx, 8 | |
| %insert = insertelement <vscale x 4 x i32> poison, i32 %shift, i32 0 | |
| %splat = shufflevector <vscale x 4 x i32> %insert, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer | |
| %add = add <vscale x 4 x i32> %splat, %rhs | |
| ret <vscale x 4 x i32> %add | |
| } | |
| declare void @dummy() | |
| declare void @use(i1) | |
| declare void @sink(i8) | |
| define i1 @udiv_by_even_divisor_ult_128(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @udiv_by_even_divisor_ult_128( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %d = and i8 %y, -2 | |
| %q = udiv i8 %x, %d | |
| %r = icmp ult i8 %q, 128 | |
| ret i1 %r | |
| } | |
| define i1 @udiv_high_known_ones_ugt_63(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @udiv_high_known_ones_ugt_63( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %n = or i8 %x, -64 | |
| %d0 = and i8 %y, 1 | |
| %d = or i8 %d0, 2 | |
| %q = udiv i8 %n, %d | |
| %r = icmp ugt i8 %q, 63 | |
| ret i1 %r | |
| } | |
| define i1 @urem_smaller_lhs_bit_identity(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @urem_smaller_lhs_bit_identity( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %l = and i8 %x, 5 | |
| %d = or i8 %y, 8 | |
| %r = urem i8 %l, %d | |
| %t = and i8 %r, 2 | |
| %c = icmp eq i8 %t, 0 | |
| ret i1 %c | |
| } | |
| define i1 @urem_smaller_lhs_known_ones_ugt_3(i8 %x, i8 %y) { | |
| ; CHECK-LABEL: @urem_smaller_lhs_known_ones_ugt_3( | |
| ; CHECK-NEXT: ret i1 true | |
| ; | |
| %l0 = and i8 %x, 1 | |
| %l = or i8 %l0, 4 | |
| %d = or i8 %y, 8 | |
| %r = urem i8 %l, %d | |
| %c = icmp ugt i8 %r, 3 | |
| ret i1 %c | |
| } |