brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 7280c27 Raw
136 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 42; RUN: opt -passes=bdce %s -S | FileCheck %s3 4; The 'nuw' on the subtract allows us to deduce that %setbit is not demanded.5; But if we change that value to '0', then the 'nuw' is no longer valid. If we don't6; remove the 'nuw', another pass (-instcombine) may make a transform based on an7; that incorrect assumption and we can miscompile:8; https://bugs.llvm.org/show_bug.cgi?id=336959 10define i1 @PR33695(i1 %b, i8 %x) {11; CHECK-LABEL: define i1 @PR33695(12; CHECK-SAME: i1 [[B:%.*]], i8 [[X:%.*]]) {13; CHECK-NEXT:    [[LITTLE_NUMBER:%.*]] = zext i1 [[B]] to i814; CHECK-NEXT:    [[BIG_NUMBER:%.*]] = shl i8 0, 115; CHECK-NEXT:    [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]16; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[SUB]] to i117; CHECK-NEXT:    ret i1 [[TRUNC]]18;19  %setbit = or i8 %x, 6420  %little_number = zext i1 %b to i821  %big_number = shl i8 %setbit, 122  %sub = sub nuw i8 %big_number, %little_number23  %trunc = trunc i8 %sub to i124  ret i1 %trunc25}26 27; Similar to above, but now with more no-wrap.28; https://bugs.llvm.org/show_bug.cgi?id=3403729 30define i64 @PR34037(i64 %m, i32 %r, i64 %j, i1 %b, i32 %k, i64 %p) {31; CHECK-LABEL: define i64 @PR34037(32; CHECK-SAME: i64 [[M:%.*]], i32 [[R:%.*]], i64 [[J:%.*]], i1 [[B:%.*]], i32 [[K:%.*]], i64 [[P:%.*]]) {33; CHECK-NEXT:    [[SHL:%.*]] = shl i64 0, 2934; CHECK-NEXT:    [[CONV1:%.*]] = select i1 [[B]], i64 7, i64 035; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[SHL]], [[CONV1]]36; CHECK-NEXT:    [[CONV2:%.*]] = zext i32 [[K]] to i6437; CHECK-NEXT:    [[MUL:%.*]] = mul i64 [[SUB]], [[CONV2]]38; CHECK-NEXT:    [[CONV4:%.*]] = and i64 [[P]], 6553539; CHECK-NEXT:    [[AND5:%.*]] = and i64 [[MUL]], [[CONV4]]40; CHECK-NEXT:    ret i64 [[AND5]]41;42  %conv = zext i32 %r to i6443  %and = and i64 %m, %conv44  %neg = xor i64 %and, 3435973836745  %or = or i64 %j, %neg46  %shl = shl i64 %or, 2947  %conv1 = select i1 %b, i64 7, i64 048  %sub = sub nuw nsw i64 %shl, %conv149  %conv2 = zext i32 %k to i6450  %mul = mul nsw i64 %sub, %conv251  %conv4 = and i64 %p, 6553552  %and5 = and i64 %mul, %conv453  ret i64 %and554}55 56; This is a manufactured example based on the 1st test to prove that the57; assumption-killing algorithm stops at the call. Ie, it does not remove58; nsw/nuw from the 'add' because a call demands all bits of its argument.59 60declare i1 @foo(i1)61 62define i1 @poison_on_call_user_is_ok(i1 %b, i8 %x) {63; CHECK-LABEL: define i1 @poison_on_call_user_is_ok(64; CHECK-SAME: i1 [[B:%.*]], i8 [[X:%.*]]) {65; CHECK-NEXT:    [[LITTLE_NUMBER:%.*]] = zext i1 [[B]] to i866; CHECK-NEXT:    [[BIG_NUMBER:%.*]] = shl i8 0, 167; CHECK-NEXT:    [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]68; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[SUB]] to i169; CHECK-NEXT:    [[CALL_RESULT:%.*]] = call i1 @foo(i1 [[TRUNC]])70; CHECK-NEXT:    [[ADD:%.*]] = add nuw nsw i1 [[CALL_RESULT]], true71; CHECK-NEXT:    [[MUL:%.*]] = mul i1 [[TRUNC]], [[ADD]]72; CHECK-NEXT:    ret i1 [[MUL]]73;74  %setbit = or i8 %x, 6475  %little_number = zext i1 %b to i876  %big_number = shl i8 %setbit, 177  %sub = sub nuw i8 %big_number, %little_number78  %trunc = trunc i8 %sub to i179  %call_result = call i1 @foo(i1 %trunc)80  %add = add nsw nuw i1 %call_result, 181  %mul = mul i1 %trunc, %add82  ret i1 %mul83}84 85 86; We were asserting that all users of a trivialized integer-type instruction were87; also integer-typed, but that's too strong. The alloca has a pointer-type result.88 89define void @PR34179(ptr %a) {90; CHECK-LABEL: define void @PR34179(91; CHECK-SAME: ptr [[A:%.*]]) {92; CHECK-NEXT:    [[T0:%.*]] = load volatile i32, ptr [[A]], align 493; CHECK-NEXT:    ret void94;95  %t0 = load volatile i32, ptr %a96  %vla = alloca i32, i32 %t097  ret void98}99 100define i64 @disjoint(i64 %x) {101; CHECK-LABEL: define i64 @disjoint(102; CHECK-SAME: i64 [[X:%.*]]) {103; CHECK-NEXT:    [[OR:%.*]] = or i64 [[X]], -2104; CHECK-NEXT:    ret i64 [[OR]]105;106  %and = and i64 %x, 1107  %or = or disjoint i64 %and, -2108  ret i64 %or109}110 111define i32 @disjoint_indirect(i64 %x) {112; CHECK-LABEL: define i32 @disjoint_indirect(113; CHECK-SAME: i64 [[X:%.*]]) {114; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i64 [[X]] to i32115; CHECK-NEXT:    [[OR:%.*]] = or i32 [[TRUNC]], -2116; CHECK-NEXT:    ret i32 [[OR]]117;118  %and = and i64 %x, 1119  %trunc = trunc i64 %and to i32120  %or = or disjoint i32 %trunc, -2121  ret i32 %or122}123 124define i32 @range(i32 %x) {125; CHECK-LABEL: define i32 @range(126; CHECK-SAME: i32 [[X:%.*]]) {127; CHECK-NEXT:    [[UMIN:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 100)128; CHECK-NEXT:    [[AND:%.*]] = and i32 [[UMIN]], -2129; CHECK-NEXT:    ret i32 [[AND]]130;131  %or = or i32 %x, 1132  %umin = call i32 @llvm.umin.i32(i32 %or, i32 100), !range !{i32 1, i32 101}133  %and = and i32 %umin, -2134  ret i32 %and135}136