Index: llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1981,7 +1981,8 @@ !isGuaranteedNotToBeUndefOrPoison(Cond)) Cond = IRB.CreateFreeze(Cond); - MergedCondition = IRB.CreateAnd(MergedCondition, Cond); + // Use logical and to avoid propagating poison from later conditions. + MergedCondition = IRB.CreateLogicalAnd(MergedCondition, Cond); } void CHR::transformScopes(SmallVectorImpl &CHRScopes) { Index: llvm/test/Transforms/PGOProfile/chr.ll =================================================================== --- llvm/test/Transforms/PGOProfile/chr.ll +++ llvm/test/Transforms/PGOProfile/chr.ll @@ -549,39 +549,40 @@ ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[I:%.*]], align 4 ; CHECK-NEXT: [[DOTFR3:%.*]] = freeze i32 [[TMP0]] -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[SUM0:%.*]], 4 +; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[DOTFR3]], 255 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0 -; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[DOTFR3]], 11 -; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], 11 -; CHECK-NEXT: [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP2]] -; CHECK-NEXT: br i1 [[TMP5]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] +; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[SUM0:%.*]], 4 +; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], 0 +; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], i1 [[TMP4]], i1 false +; CHECK-NEXT: [[TMP6:%.*]] = and i32 [[DOTFR3]], 11 +; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i32 [[TMP6]], 11 +; CHECK-NEXT: [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP5]] +; CHECK-NEXT: br i1 [[TMP8]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] ; CHECK: bb0: -; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[SUM0]], 85 -; CHECK-NEXT: [[TMP7:%.*]] = add i32 [[SUM0]], 173 +; CHECK-NEXT: [[TMP9:%.*]] = add i32 [[SUM0]], 85 +; CHECK-NEXT: [[TMP10:%.*]] = add i32 [[SUM0]], 173 ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: entry.split.nonchr: -; CHECK-NEXT: [[TMP8:%.*]] = and i32 [[DOTFR3]], 255 -; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP8]], 0 -; CHECK-NEXT: br i1 [[DOTNOT]], label [[BB3]], label [[BB0_NONCHR:%.*]], !prof [[PROF16]] +; CHECK-NEXT: br i1 [[TMP2]], label [[BB0_NONCHR:%.*]], label [[BB3]], !prof [[PROF17:![0-9]+]] ; CHECK: bb0.nonchr: -; CHECK-NEXT: [[TMP9:%.*]] = and i32 [[DOTFR3]], 1 -; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i32 [[TMP9]], 0 -; CHECK-NEXT: [[TMP11:%.*]] = add i32 [[SUM0]], 42 -; CHECK-NEXT: [[SUM1_NONCHR:%.*]] = select i1 [[TMP10]], i32 [[SUM0]], i32 [[TMP11]], !prof [[PROF16]] -; CHECK-NEXT: [[TMP12:%.*]] = and i32 [[DOTFR3]], 2 -; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i32 [[TMP12]], 0 -; CHECK-NEXT: [[TMP14:%.*]] = add i32 [[SUM1_NONCHR]], 43 -; CHECK-NEXT: [[SUM2_NONCHR:%.*]] = select i1 [[TMP13]], i32 [[SUM1_NONCHR]], i32 [[TMP14]], !prof [[PROF16]] -; CHECK-NEXT: [[TMP15:%.*]] = and i32 [[SUM0]], 4 -; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[TMP15]], 0 -; CHECK-NEXT: [[TMP17:%.*]] = and i32 [[DOTFR3]], 8 +; CHECK-NEXT: [[TMP11:%.*]] = and i32 [[DOTFR3]], 1 +; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i32 [[TMP11]], 0 +; CHECK-NEXT: [[TMP13:%.*]] = add i32 [[SUM0]], 42 +; CHECK-NEXT: [[SUM1_NONCHR:%.*]] = select i1 [[TMP12]], i32 [[SUM0]], i32 [[TMP13]], !prof [[PROF16]] +; CHECK-NEXT: [[TMP14:%.*]] = and i32 [[DOTFR3]], 2 +; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i32 [[TMP14]], 0 +; CHECK-NEXT: [[TMP16:%.*]] = add i32 [[SUM1_NONCHR]], 43 +; CHECK-NEXT: [[SUM2_NONCHR:%.*]] = select i1 [[TMP15]], i32 [[SUM1_NONCHR]], i32 [[TMP16]], !prof [[PROF16]] +; CHECK-NEXT: [[TMP17:%.*]] = and i32 [[SUM0]], 4 ; CHECK-NEXT: [[TMP18:%.*]] = icmp eq i32 [[TMP17]], 0 -; CHECK-NEXT: [[SUM4_NONCHR_V:%.*]] = select i1 [[TMP18]], i32 44, i32 88 +; CHECK-NEXT: [[TMP19:%.*]] = and i32 [[DOTFR3]], 8 +; CHECK-NEXT: [[TMP20:%.*]] = icmp eq i32 [[TMP19]], 0 +; CHECK-NEXT: [[SUM4_NONCHR_V:%.*]] = select i1 [[TMP20]], i32 44, i32 88 ; CHECK-NEXT: [[SUM4_NONCHR:%.*]] = add i32 [[SUM2_NONCHR]], [[SUM4_NONCHR_V]] -; CHECK-NEXT: [[SUM5_NONCHR:%.*]] = select i1 [[TMP16]], i32 [[SUM2_NONCHR]], i32 [[SUM4_NONCHR]], !prof [[PROF16]] +; CHECK-NEXT: [[SUM5_NONCHR:%.*]] = select i1 [[TMP18]], i32 [[SUM2_NONCHR]], i32 [[SUM4_NONCHR]], !prof [[PROF16]] ; CHECK-NEXT: br label [[BB3]] ; CHECK: bb3: -; CHECK-NEXT: [[SUM6:%.*]] = phi i32 [ [[TMP7]], [[BB0]] ], [ [[SUM0]], [[ENTRY_SPLIT_NONCHR]] ], [ [[SUM5_NONCHR]], [[BB0_NONCHR]] ] +; CHECK-NEXT: [[SUM6:%.*]] = phi i32 [ [[TMP10]], [[BB0]] ], [ [[SUM0]], [[ENTRY_SPLIT_NONCHR]] ], [ [[SUM5_NONCHR]], [[BB0_NONCHR]] ] ; CHECK-NEXT: ret i32 [[SUM6]] ; entry: @@ -651,20 +652,21 @@ ; CHECK-NEXT: [[I0:%.*]] = load i32, i32* [[I:%.*]], align 4 ; CHECK-NEXT: [[I0_FR:%.*]] = freeze i32 [[I0]] ; CHECK-NEXT: [[J0:%.*]] = load i32, i32* [[J:%.*]], align 4 +; CHECK-NEXT: [[V1:%.*]] = and i32 [[I0_FR]], 255 +; CHECK-NEXT: [[V2:%.*]] = icmp ne i32 [[V1]], 0 ; CHECK-NEXT: [[V9:%.*]] = and i32 [[J0]], 4 ; CHECK-NEXT: [[V10:%.*]] = icmp ne i32 [[V9]], 0 -; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[I0_FR]], 10 -; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 10 -; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[V10]] -; CHECK-NEXT: br i1 [[TMP2]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] +; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[V2]], i1 [[V10]], i1 false +; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[I0_FR]], 10 +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 10 +; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP0]] +; CHECK-NEXT: br i1 [[TMP3]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] ; CHECK: bb0: ; CHECK-NEXT: [[V8:%.*]] = add i32 [[SUM0:%.*]], 43 ; CHECK-NEXT: [[V13:%.*]] = add i32 [[SUM0]], 131 ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: entry.split.nonchr: -; CHECK-NEXT: [[V1:%.*]] = and i32 [[I0_FR]], 255 -; CHECK-NEXT: [[V2_NOT:%.*]] = icmp eq i32 [[V1]], 0 -; CHECK-NEXT: br i1 [[V2_NOT]], label [[BB3]], label [[BB0_NONCHR:%.*]], !prof [[PROF16]] +; CHECK-NEXT: br i1 [[V2]], label [[BB0_NONCHR:%.*]], label [[BB3]], !prof [[PROF17]] ; CHECK: bb0.nonchr: ; CHECK-NEXT: [[V3_NONCHR:%.*]] = and i32 [[I0_FR]], 2 ; CHECK-NEXT: [[V4_NONCHR:%.*]] = icmp eq i32 [[V3_NONCHR]], 0 @@ -877,14 +879,14 @@ ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[I:%.*]], align 4 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[TMP0]], 1 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: br i1 [[TMP2]], label [[BB1:%.*]], label [[BB0:%.*]], !prof [[PROF17:![0-9]+]] +; CHECK-NEXT: br i1 [[TMP2]], label [[BB1:%.*]], label [[BB0:%.*]], !prof [[PROF18:![0-9]+]] ; CHECK: bb0: ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB1]] ; CHECK: bb1: ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP0]], 2 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], 0 -; CHECK-NEXT: br i1 [[TMP4]], label [[BB3:%.*]], label [[BB2:%.*]], !prof [[PROF17]] +; CHECK-NEXT: br i1 [[TMP4]], label [[BB3:%.*]], label [[BB2:%.*]], !prof [[PROF18]] ; CHECK: bb2: ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB3]] @@ -1123,14 +1125,14 @@ ; CHECK-NEXT: [[MUL16:%.*]] = fmul double [[DIV]], [[CONV]] ; CHECK-NEXT: [[CONV717:%.*]] = fptosi double [[MUL16]] to i32 ; CHECK-NEXT: [[CMP18:%.*]] = icmp sgt i32 [[CONV717]], 0 -; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[CMP18]] +; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i1 [[CMP18]], i1 false ; CHECK-NEXT: br i1 [[TMP3]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] ; CHECK: bb0: ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: entry.split.nonchr: -; CHECK-NEXT: br i1 [[TMP2]], label [[BB0_NONCHR:%.*]], label [[BB1_NONCHR:%.*]], !prof [[PROF18:![0-9]+]] +; CHECK-NEXT: br i1 [[TMP2]], label [[BB0_NONCHR:%.*]], label [[BB1_NONCHR:%.*]], !prof [[PROF17]] ; CHECK: bb0.nonchr: ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB1_NONCHR]] @@ -1201,7 +1203,7 @@ ; CHECK-NEXT: [[TMP14:%.*]] = add i32 [[SUM2]], 88 ; CHECK-NEXT: br label [[BB3]] ; CHECK: bb0.split.nonchr: -; CHECK-NEXT: br i1 [[TMP10]], label [[BB1_NONCHR:%.*]], label [[BB3]], !prof [[PROF18]] +; CHECK-NEXT: br i1 [[TMP10]], label [[BB1_NONCHR:%.*]], label [[BB3]], !prof [[PROF17]] ; CHECK: bb1.nonchr: ; CHECK-NEXT: [[TMP15:%.*]] = and i32 [[DOTFR1]], 8 ; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[TMP15]], 0 @@ -1919,8 +1921,8 @@ ; CHECK-NEXT: [[CMP0:%.*]] = icmp ne i64 [[J:%.*]], [[K:%.*]] ; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[J]], [[I:%.*]] ; CHECK-NEXT: [[CMP_I:%.*]] = icmp ne i64 [[I]], 86 -; CHECK-NEXT: [[TMP0:%.*]] = and i1 [[CMP0]], [[CMP3]] -; CHECK-NEXT: [[TMP1:%.*]] = and i1 [[TMP0]], [[CMP_I]] +; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[CMP0]], i1 [[CMP3]], i1 false +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i1 [[CMP_I]], i1 false ; CHECK-NEXT: br i1 [[TMP1]], label [[BB1:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15]] ; CHECK: bb1: ; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i64 [[I]], 2 @@ -1936,7 +1938,7 @@ ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB3_NONCHR2]] ; CHECK: bb3.nonchr2: -; CHECK-NEXT: br i1 [[CMP_I]], label [[BB4_NONCHR3:%.*]], label [[BB7]], !prof [[PROF18]] +; CHECK-NEXT: br i1 [[CMP_I]], label [[BB4_NONCHR3:%.*]], label [[BB7]], !prof [[PROF17]] ; CHECK: bb4.nonchr3: ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB7]] @@ -1945,7 +1947,7 @@ ; CHECK-NEXT: call void @foo() ; CHECK-NEXT: br label [[BB10:%.*]] ; CHECK: entry.split.nonchr: -; CHECK-NEXT: br i1 [[CMP0]], label [[BB1_NONCHR:%.*]], label [[BB10]], !prof [[PROF18]] +; CHECK-NEXT: br i1 [[CMP0]], label [[BB1_NONCHR:%.*]], label [[BB10]], !prof [[PROF17]] ; CHECK: bb1.nonchr: ; CHECK-NEXT: [[CMP2_NONCHR:%.*]] = icmp eq i64 [[I]], 2 ; CHECK-NEXT: br i1 [[CMP2_NONCHR]], label [[BB3_NONCHR:%.*]], label [[BB2_NONCHR:%.*]], !prof [[PROF16]] @@ -2683,5 +2685,5 @@ !17 = !{!"branch_weights", i32 0, i32 0} ; CHECK: !15 = !{!"branch_weights", i32 1000, i32 0} ; CHECK: !16 = !{!"branch_weights", i32 0, i32 1} -; CHECK: !17 = !{!"branch_weights", i32 1, i32 1} -; CHECK: !18 = !{!"branch_weights", i32 1, i32 0} +; CHECK: !17 = !{!"branch_weights", i32 1, i32 0} +; CHECK: !18 = !{!"branch_weights", i32 1, i32 1}