131 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -O3 -S < %s | FileCheck %s3; RUN: opt -passes="default<O3>" -S < %s | FileCheck %s4 5; These are tests that check for set/clear bits in a bitfield based on PR37098:6; https://bugs.llvm.org/show_bug.cgi?id=370987;8; The initial IR from clang has been transformed by SROA, but no other passes9; have run yet. In all cases, we should reduce these to a mask and compare10; instead of shift/cast/logic ops.11;12; Currently, this happens mostly through a combination of instcombine and13; aggressive-instcombine. If pass ordering changes, we may have to adjust14; the pattern matching in 1 or both of those passes.15 16; Legal i32 is required to allow casting transforms that eliminate the zexts.17target datalayout = "n32"18 19define i32 @allclear(i32 %a) {20; CHECK-LABEL: @allclear(21; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1522; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 023; CHECK-NEXT: [[TMP3:%.*]] = zext i1 [[TMP2]] to i3224; CHECK-NEXT: ret i32 [[TMP3]]25;26 %a.sroa.0.0.trunc = trunc i32 %a to i827 %a.sroa.5.0.shift = lshr i32 %a, 828 %bf.clear = and i8 %a.sroa.0.0.trunc, 129 %bf.cast = zext i8 %bf.clear to i3230 %bf.lshr = lshr i8 %a.sroa.0.0.trunc, 131 %bf.clear2 = and i8 %bf.lshr, 132 %bf.cast3 = zext i8 %bf.clear2 to i3233 %or = or i32 %bf.cast, %bf.cast334 %bf.lshr5 = lshr i8 %a.sroa.0.0.trunc, 235 %bf.clear6 = and i8 %bf.lshr5, 136 %bf.cast7 = zext i8 %bf.clear6 to i3237 %or8 = or i32 %or, %bf.cast738 %bf.lshr10 = lshr i8 %a.sroa.0.0.trunc, 339 %bf.clear11 = and i8 %bf.lshr10, 140 %bf.cast12 = zext i8 %bf.clear11 to i3241 %or13 = or i32 %or8, %bf.cast1242 %cmp = icmp eq i32 %or13, 043 %conv = zext i1 %cmp to i3244 ret i32 %conv45}46 47define i32 @anyset(i32 %a) {48; CHECK-LABEL: @anyset(49; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1550; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 051; CHECK-NEXT: [[TMP3:%.*]] = zext i1 [[TMP2]] to i3252; CHECK-NEXT: ret i32 [[TMP3]]53;54 %a.sroa.0.0.trunc = trunc i32 %a to i855 %a.sroa.5.0.shift = lshr i32 %a, 856 %bf.clear = and i8 %a.sroa.0.0.trunc, 157 %bf.cast = zext i8 %bf.clear to i3258 %bf.lshr = lshr i8 %a.sroa.0.0.trunc, 159 %bf.clear2 = and i8 %bf.lshr, 160 %bf.cast3 = zext i8 %bf.clear2 to i3261 %or = or i32 %bf.cast, %bf.cast362 %bf.lshr5 = lshr i8 %a.sroa.0.0.trunc, 263 %bf.clear6 = and i8 %bf.lshr5, 164 %bf.cast7 = zext i8 %bf.clear6 to i3265 %or8 = or i32 %or, %bf.cast766 %bf.lshr10 = lshr i8 %a.sroa.0.0.trunc, 367 %bf.clear11 = and i8 %bf.lshr10, 168 %bf.cast12 = zext i8 %bf.clear11 to i3269 %or13 = or i32 %or8, %bf.cast1270 %cmp = icmp ne i32 %or13, 071 %conv = zext i1 %cmp to i3272 ret i32 %conv73}74 75define i32 @allset(i32 %a) {76; CHECK-LABEL: @allset(77; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1578; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1579; CHECK-NEXT: [[TMP3:%.*]] = zext i1 [[TMP2]] to i3280; CHECK-NEXT: ret i32 [[TMP3]]81;82 %a.sroa.0.0.trunc = trunc i32 %a to i883 %a.sroa.5.0.shift = lshr i32 %a, 884 %bf.clear = and i8 %a.sroa.0.0.trunc, 185 %bf.cast = zext i8 %bf.clear to i3286 %bf.lshr = lshr i8 %a.sroa.0.0.trunc, 187 %bf.clear2 = and i8 %bf.lshr, 188 %bf.cast3 = zext i8 %bf.clear2 to i3289 %and = and i32 %bf.cast, %bf.cast390 %bf.lshr5 = lshr i8 %a.sroa.0.0.trunc, 291 %bf.clear6 = and i8 %bf.lshr5, 192 %bf.cast7 = zext i8 %bf.clear6 to i3293 %and8 = and i32 %and, %bf.cast794 %bf.lshr10 = lshr i8 %a.sroa.0.0.trunc, 395 %bf.clear11 = and i8 %bf.lshr10, 196 %bf.cast12 = zext i8 %bf.clear11 to i3297 %and13 = and i32 %and8, %bf.cast1298 %cmp = icmp ne i32 %and13, 099 %conv = zext i1 %cmp to i32100 ret i32 %conv101}102 103define i32 @anyclear(i32 %a) {104; CHECK-LABEL: @anyclear(105; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 15106; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 15107; CHECK-NEXT: [[TMP3:%.*]] = zext i1 [[TMP2]] to i32108; CHECK-NEXT: ret i32 [[TMP3]]109;110 %a.sroa.0.0.trunc = trunc i32 %a to i8111 %a.sroa.5.0.shift = lshr i32 %a, 8112 %bf.clear = and i8 %a.sroa.0.0.trunc, 1113 %bf.cast = zext i8 %bf.clear to i32114 %bf.lshr = lshr i8 %a.sroa.0.0.trunc, 1115 %bf.clear2 = and i8 %bf.lshr, 1116 %bf.cast3 = zext i8 %bf.clear2 to i32117 %and = and i32 %bf.cast, %bf.cast3118 %bf.lshr5 = lshr i8 %a.sroa.0.0.trunc, 2119 %bf.clear6 = and i8 %bf.lshr5, 1120 %bf.cast7 = zext i8 %bf.clear6 to i32121 %and8 = and i32 %and, %bf.cast7122 %bf.lshr10 = lshr i8 %a.sroa.0.0.trunc, 3123 %bf.clear11 = and i8 %bf.lshr10, 1124 %bf.cast12 = zext i8 %bf.clear11 to i32125 %and13 = and i32 %and8, %bf.cast12126 %cmp = icmp eq i32 %and13, 0127 %conv = zext i1 %cmp to i32128 ret i32 %conv129}130 131