|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: opt -S -passes=gvn %s | FileCheck %s |
| 3 | + |
| 4 | +; NOTE: A test to confirm GVN doesn't introduce phis for token like types. |
| 5 | +; NOTE: This implies the CHECKS should exactly match the IR. |
| 6 | + |
| 7 | +%"$Globals" = type { i32 } |
| 8 | +@CBV = external constant %"$Globals" |
| 9 | +@Out.str = private unnamed_addr constant [4 x i8] c"Out\00", align 1 |
| 10 | + |
| 11 | +define i32 @CSMain() local_unnamed_addr { |
| 12 | +; CHECK-LABEL: define i32 @CSMain() local_unnamed_addr { |
| 13 | +; CHECK-NEXT: [[ENTRY:.*:]] |
| 14 | +; CHECK-NEXT: [[LOADGLOBAL:%.*]] = load i32, ptr @CBV, align 4 |
| 15 | +; CHECK-NEXT: [[CMP_I1_NOT:%.*]] = icmp eq i32 [[LOADGLOBAL]], 0 |
| 16 | +; CHECK-NEXT: br i1 [[CMP_I1_NOT]], label %[[CSMAIN_EXIT:.*]], label %[[FOR_BODY_I_LR_PH:.*]] |
| 17 | +; CHECK: [[FOR_BODY_I_LR_PH]]: |
| 18 | +; CHECK-NEXT: [[BUF:%.*]] = tail call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i32_1_0t(i32 0, i32 0, i32 4, i32 [[LOADGLOBAL]], ptr nonnull @Out.str) |
| 19 | +; CHECK-NEXT: br label %[[FOR_BODY_I:.*]] |
| 20 | +; CHECK: [[FOR_BODY_I]]: |
| 21 | +; CHECK-NEXT: [[LOOPPHI:%.*]] = phi i32 [ 0, %[[FOR_BODY_I_LR_PH]] ], [ [[INC_I:%.*]], %[[FOR_BODY_I]] ] |
| 22 | +; CHECK-NEXT: [[UPDATECNT:%.*]] = tail call noundef i32 @llvm.dx.resource.updatecounter.tdx.RawBuffer_i32_1_0t(target("dx.RawBuffer", i32, 1, 0) [[BUF]], i8 1) |
| 23 | +; CHECK-NEXT: [[INC_I]] = add nuw nsw i32 [[LOOPPHI]], 1 |
| 24 | +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC_I]], [[LOADGLOBAL]] |
| 25 | +; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_BODY_I]], label %[[CSMAIN_EXIT]] |
| 26 | +; CHECK: [[CSMAIN_EXIT]]: |
| 27 | +; CHECK-NEXT: [[BUFEXIT:%.*]] = tail call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i32_1_0t(i32 0, i32 0, i32 4, i32 [[LOADGLOBAL]], ptr nonnull @Out.str) |
| 28 | +; CHECK-NEXT: [[UPDATECNTEXIT:%.*]] = tail call noundef i32 @llvm.dx.resource.updatecounter.tdx.RawBuffer_i32_1_0t(target("dx.RawBuffer", i32, 1, 0) [[BUFEXIT]], i8 1) |
| 29 | +; CHECK-NEXT: ret i32 [[UPDATECNTEXIT]] |
| 30 | +; |
| 31 | +entry: |
| 32 | + %loadGlobal = load i32, ptr @CBV, align 4 |
| 33 | + %cmp.i1.not = icmp eq i32 %loadGlobal, 0 |
| 34 | + br i1 %cmp.i1.not, label %CSMain.exit, label %for.body.i.lr.ph |
| 35 | + |
| 36 | +for.body.i.lr.ph: |
| 37 | + %buf = tail call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 4, i32 %loadGlobal, ptr nonnull @Out.str) |
| 38 | + br label %for.body.i |
| 39 | + |
| 40 | +for.body.i: |
| 41 | + %loopPhi = phi i32 [ 0, %for.body.i.lr.ph ], [ %inc.i, %for.body.i ] |
| 42 | + %updateCnt = tail call noundef i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", i32, 1, 0) %buf, i8 1) |
| 43 | + %inc.i = add nuw nsw i32 %loopPhi, 1 |
| 44 | + %exitcond = icmp ne i32 %inc.i, %loadGlobal |
| 45 | + br i1 %exitcond, label %for.body.i, label %CSMain.exit |
| 46 | + |
| 47 | +CSMain.exit: |
| 48 | + %bufExit = tail call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 4, i32 %loadGlobal, ptr nonnull @Out.str) |
| 49 | + %updateCntExit = tail call noundef i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", i32, 1, 0) %bufExit, i8 1) |
| 50 | + ret i32 %updateCntExit |
| 51 | +} |
0 commit comments