64 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -O1 -S < %s | FileCheck %s3 4; Make sure we reassociate and1 with and2 before instcombine to allow5; Demorgan logic fold:6; (a & ~b) & ~c --> a & ~(b | c)7define i4 @not_reassociate_and_and_not(i4 %a, i4 %b, i4 %c, i4 %d) {8; CHECK-LABEL: @not_reassociate_and_and_not(9; CHECK-NEXT: [[TMP1:%.*]] = or i4 [[B:%.*]], [[C:%.*]]10; CHECK-NEXT: [[TMP2:%.*]] = xor i4 [[TMP1]], -111; CHECK-NEXT: [[AND2:%.*]] = and i4 [[A:%.*]], [[TMP2]]12; CHECK-NEXT: [[AND3:%.*]] = and i4 [[AND2]], [[D:%.*]]13; CHECK-NEXT: ret i4 [[AND3]]14;15 %notb = xor i4 %b, -116 %notc = xor i4 %c, -117 %and1 = and i4 %a, %notb18 %and2 = and i4 %and1, %d19 %and3 = and i4 %and2, %notc20 ret i4 %and321}22 23; (a | ~b) | ~c --> a | ~(b & c)24define i32 @not_reassociate_or_or_not(i32 %a, i32 %b, i32 %c, i32 %d) {25; CHECK-LABEL: @not_reassociate_or_or_not(26; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[B:%.*]], [[C:%.*]]27; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -128; CHECK-NEXT: [[B2:%.*]] = or i32 [[A:%.*]], [[TMP2]]29; CHECK-NEXT: [[B3:%.*]] = or i32 [[B2]], [[D:%.*]]30; CHECK-NEXT: ret i32 [[B3]]31;32 %notb = xor i32 %b, -133 %notc = xor i32 %c, -134 %b1 = or i32 %a, %notb35 %b2 = or i32 %b1, %d36 %b3 = or i32 %b2, %notc37 ret i32 %b338}39 40define i32 @PR58137_sdiv(i32 %a, i32 %b) {41; CHECK-LABEL: @PR58137_sdiv(42; CHECK-NEXT: ret i32 [[B:%.*]]43;44 %mul = mul nsw i32 2, %b45 %mul1 = mul nsw i32 %mul, %a46 %mul2 = mul nsw i32 2, %a47 %div = sdiv i32 %mul1, %mul248 ret i32 %div49}50 51define i32 @PR58137_udiv(i32 %x, i32 %y) {52; CHECK-LABEL: @PR58137_udiv(53; CHECK-NEXT: ret i32 [[X:%.*]]54;55 %zx = zext i32 %x to i6456 %zy = zext i32 %y to i6457 %m1 = mul nuw i64 %zx, %zy58 %m2 = mul nuw i64 4, %m159 %m3 = mul nuw i64 4, %zy60 %d = udiv i64 %m2, %m361 %t = trunc i64 %d to i3262 ret i32 %t63}64