169 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 62; RUN: opt -S -o - -passes=gvn %s | FileCheck %s --check-prefixes=CHECK,MDEP3; RUN: opt -S -o - -passes='gvn<memoryssa>' %s | FileCheck %s --check-prefixes=CHECK,MSSA4 5target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"6 7%struct.S1 = type { i32, i32 }8 9@a2 = common global ptr null, align 810@a = common global ptr null, align 811@s1 = common global %struct.S1 zeroinitializer, align 812 13; Check that GVN doesn't determine %2 is partially redundant.14 15define i32 @volatile_load(i32 %n) {16; CHECK-LABEL: define i32 @volatile_load(17; CHECK-SAME: i32 [[N:%.*]]) {18; CHECK-NEXT: [[ENTRY:.*]]:19; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N]], 020; CHECK-NEXT: br i1 [[CMP6]], label %[[FOR_BODY_LR_PH:.*]], label %[[FOR_END:.*]]21; CHECK: [[FOR_BODY_LR_PH]]:22; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr @a2, align 8, !tbaa [[ANYPTR_TBAA5:![0-9]+]]23; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr @a, align 8, !tbaa [[ANYPTR_TBAA5]]24; CHECK-NEXT: br label %[[FOR_BODY:.*]]25; CHECK: [[FOR_BODY]]:26; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[FOR_BODY_LR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]27; CHECK-NEXT: [[S_09:%.*]] = phi i32 [ 0, %[[FOR_BODY_LR_PH]] ], [ [[ADD:%.*]], %[[FOR_BODY]] ]28; CHECK-NEXT: [[P_08:%.*]] = phi ptr [ [[TMP0]], %[[FOR_BODY_LR_PH]] ], [ [[INCDEC_PTR:%.*]], %[[FOR_BODY]] ]29; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[P_08]], align 4, !tbaa [[INT_TBAA9:![0-9]+]]30; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i64 [[INDVARS_IV]]31; CHECK-NEXT: store i32 [[TMP2]], ptr [[ARRAYIDX]], align 4, !tbaa [[INT_TBAA9]]32; CHECK-NEXT: [[TMP3:%.*]] = load volatile i32, ptr [[P_08]], align 4, !tbaa [[INT_TBAA9]]33; CHECK-NEXT: [[ADD]] = add nsw i32 [[TMP3]], [[S_09]]34; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 135; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i32, ptr [[P_08]], i64 136; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i3237; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]38; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_BODY]], label %[[FOR_COND_FOR_END_CRIT_EDGE:.*]]39; CHECK: [[FOR_COND_FOR_END_CRIT_EDGE]]:40; CHECK-NEXT: br label %[[FOR_END]]41; CHECK: [[FOR_END]]:42; CHECK-NEXT: [[S_0_LCSSA:%.*]] = phi i32 [ [[ADD]], %[[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, %[[ENTRY]] ]43; CHECK-NEXT: ret i32 [[S_0_LCSSA]]44;45entry:46 %cmp6 = icmp sgt i32 %n, 047 br i1 %cmp6, label %for.body.lr.ph, label %for.end48 49for.body.lr.ph:50 %0 = load ptr, ptr @a2, align 8, !tbaa !151 %1 = load ptr, ptr @a, align 8, !tbaa !152 br label %for.body53 54for.body:55 %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]56 %s.09 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ]57 %p.08 = phi ptr [ %0, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]58 %2 = load i32, ptr %p.08, align 4, !tbaa !559 %arrayidx = getelementptr inbounds i32, ptr %1, i64 %indvars.iv60 store i32 %2, ptr %arrayidx, align 4, !tbaa !561 %3 = load volatile i32, ptr %p.08, align 4, !tbaa !562 %add = add nsw i32 %3, %s.0963 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 164 %incdec.ptr = getelementptr inbounds i32, ptr %p.08, i64 165 %lftr.wideiv = trunc i64 %indvars.iv.next to i3266 %exitcond = icmp ne i32 %lftr.wideiv, %n67 br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge68 69for.cond.for.end_crit_edge:70 %add.lcssa = phi i32 [ %add, %for.body ]71 br label %for.end72 73for.end:74 %s.0.lcssa = phi i32 [ %add.lcssa, %for.cond.for.end_crit_edge ], [ 0, %entry ]75 ret i32 %s.0.lcssa76}77 78; %1 is partially redundant if %0 can be widened to a 64-bit load.79; But we should not widen %0 to 64-bit load.80 81define i32 @overaligned_load(i32 %a, ptr nocapture %b) !dbg !13 {82; CHECK-LABEL: define i32 @overaligned_load(83; CHECK-SAME: i32 [[A:%.*]], ptr captures(none) [[B:%.*]]) !dbg [[DBG11:![0-9]+]] {84; CHECK-NEXT: [[ENTRY:.*:]]85; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], 0, !dbg [[DBG14:![0-9]+]]86; CHECK-NEXT: br i1 [[CMP]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]], !dbg [[DBG14]]87; CHECK: [[IF_THEN]]:88; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @s1, align 8, !dbg [[DBG15:![0-9]+]], !tbaa [[INT_TBAA9]]89; CHECK-NEXT: br label %[[IF_END:.*]], !dbg [[DBG15]]90; CHECK: [[IF_ELSE]]:91; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 2, !dbg [[DBG16:![0-9]+]]92; CHECK-NEXT: store i32 10, ptr [[ARRAYIDX]], align 4, !dbg [[DBG16]], !tbaa [[INT_TBAA9]]93; CHECK-NEXT: br label %[[IF_END]], !dbg [[DBG16]]94; CHECK: [[IF_END]]:95; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ [[TMP0]], %[[IF_THEN]] ], [ 0, %[[IF_ELSE]] ]96; CHECK-NEXT: [[P_0:%.*]] = phi ptr [ @s1, %[[IF_THEN]] ], [ [[B]], %[[IF_ELSE]] ]97; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P_0]], i64 1, !dbg [[DBG17:![0-9]+]]98; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ADD_PTR]], align 4, !dbg [[DBG17]], !tbaa [[INT_TBAA9]]99; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[TMP1]], [[I_0]], !dbg [[DBG17]]100; CHECK-NEXT: ret i32 [[ADD1]], !dbg [[DBG17]]101;102entry:103 %cmp = icmp sgt i32 %a, 0, !dbg !14104 br i1 %cmp, label %if.then, label %if.else, !dbg !14105 106if.then:107 %0 = load i32, ptr @s1, align 8, !tbaa !5, !dbg !15108 br label %if.end, !dbg !15109 110if.else:111 %arrayidx = getelementptr inbounds i32, ptr %b, i64 2, !dbg !16112 store i32 10, ptr %arrayidx, align 4, !tbaa !5, !dbg !16113 br label %if.end, !dbg !16114 115if.end:116 %i.0 = phi i32 [ %0, %if.then ], [ 0, %if.else ]117 %p.0 = phi ptr [ @s1, %if.then ], [ %b, %if.else ]118 %add.ptr = getelementptr inbounds i32, ptr %p.0, i64 1, !dbg !17119 %1 = load i32, ptr %add.ptr, align 4, !tbaa !5, !dbg !17120 %add1 = add nsw i32 %1, %i.0, !dbg !17121 ret i32 %add1, !dbg !17122}123 124!1 = !{!2, !2, i64 0}125!2 = !{!"any pointer", !3, i64 0}126!3 = !{!"omnipotent char", !4, i64 0}127!4 = !{!"Simple C/C++ TBAA"}128!5 = !{!6, !6, i64 0}129!6 = !{!"int", !3, i64 0}130 131!llvm.module.flags = !{!7, !8, !9}132!llvm.dbg.cu = !{!18}133!7 = !{i32 2, !"Dwarf Version", i32 4}134!8 = !{i32 2, !"Debug Info Version", i32 3}135!9 = !{i32 1, !"PIC Level", i32 2}136 137!10 = !{}138!11 = !DISubroutineType(types: !10)139!12 = !DIFile(filename: "test.cpp", directory: "/tmp")140!13 = distinct !DISubprogram(name: "test", scope: !12, file: !12, line: 99, type: !11, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, unit: !18, retainedNodes: !10)141!14 = !DILocation(line: 100, column: 1, scope: !13)142!15 = !DILocation(line: 101, column: 1, scope: !13)143!16 = !DILocation(line: 102, column: 1, scope: !13)144!17 = !DILocation(line: 103, column: 1, scope: !13)145!18 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",146 file: !12,147 isOptimized: true, flags: "-O2",148 splitDebugFilename: "abc.debug", emissionKind: 2)149;.150; CHECK: [[META3:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META4:![0-9]+]], producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 0, splitDebugFilename: "abc.debug", emissionKind: LineTablesOnly)151; CHECK: [[META4]] = !DIFile(filename: "{{.*}}test.cpp", directory: {{.*}})152; CHECK: [[ANYPTR_TBAA5]] = !{[[META6:![0-9]+]], [[META6]], i64 0}153; CHECK: [[META6]] = !{!"any pointer", [[META7:![0-9]+]], i64 0}154; CHECK: [[META7]] = !{!"omnipotent char", [[META8:![0-9]+]], i64 0}155; CHECK: [[META8]] = !{!"Simple C/C++ TBAA"}156; CHECK: [[INT_TBAA9]] = !{[[META10:![0-9]+]], [[META10]], i64 0}157; CHECK: [[META10]] = !{!"int", [[META7]], i64 0}158; CHECK: [[DBG11]] = distinct !DISubprogram(name: "test", scope: [[META4]], file: [[META4]], line: 99, type: [[META12:![0-9]+]], scopeLine: 100, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META3]], retainedNodes: [[META13:![0-9]+]])159; CHECK: [[META12]] = !DISubroutineType(types: [[META13]])160; CHECK: [[META13]] = !{}161; CHECK: [[DBG14]] = !DILocation(line: 100, column: 1, scope: [[DBG11]])162; CHECK: [[DBG15]] = !DILocation(line: 101, column: 1, scope: [[DBG11]])163; CHECK: [[DBG16]] = !DILocation(line: 102, column: 1, scope: [[DBG11]])164; CHECK: [[DBG17]] = !DILocation(line: 103, column: 1, scope: [[DBG11]])165;.166;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:167; MDEP: {{.*}}168; MSSA: {{.*}}169