Index: llvm/lib/Analysis/LazyValueInfo.cpp =================================================================== --- llvm/lib/Analysis/LazyValueInfo.cpp +++ llvm/lib/Analysis/LazyValueInfo.cpp @@ -819,6 +819,8 @@ if (!OptTrueVal) return None; ValueLatticeElement &TrueVal = *OptTrueVal; + intersectAssumeOrGuardBlockValueConstantRange(SI->getTrueValue(), TrueVal, + SI); // If we hit overdefined, don't ask more queries. We want to avoid poisoning // extra slots in the table if we can. @@ -830,6 +832,8 @@ if (!OptFalseVal) return None; ValueLatticeElement &FalseVal = *OptFalseVal; + intersectAssumeOrGuardBlockValueConstantRange(SI->getFalseValue(), FalseVal, + SI); // If we hit overdefined, don't ask more queries. We want to avoid poisoning // extra slots in the table if we can. @@ -1798,8 +1802,14 @@ if (CxtI) { BasicBlock *BB = CxtI->getParent(); - // Function entry or an unreachable block. Bail to avoid confusing - // analysis below. + // Analysis value in function entry. + if (BB == &BB->getParent()->getEntryBlock()) { + ValueLatticeElement Result = + getImpl(PImpl, AC, &DL).getValueInBlock(V, BB, CxtI); + return getPredicateResult(Pred, C, Result, DL, TLI); + } + + // An unreachable block. Bail to avoid confusing analysis below. pred_iterator PI = pred_begin(BB), PE = pred_end(BB); if (PI == PE) return Unknown; Index: llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll =================================================================== --- llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll +++ llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll @@ -381,7 +381,7 @@ ; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[MUL]], 32 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[SHR]] to i32 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[TRUNC]], 7 -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %zext = zext i32 %x to i64 %mul = mul nuw i64 %zext, 7 @@ -397,7 +397,7 @@ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i64 [[ZEXT]], 128 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[ADD]], 384 ; CHECK-NEXT: store i64 [[ADD]], i64* [[P:%.*]] -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %zext = zext i8 %x to i64 %add = add nuw nsw i64 %zext, 128 Index: llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll =================================================================== --- llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll +++ llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll @@ -93,7 +93,7 @@ define void @test4(i8* %dest, i8* %src) { ; CHECK-LABEL: @test4( -; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[DEST:%.*]], i8* [[SRC:%.*]], i32 1, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull [[DEST:%.*]], i8* nonnull [[SRC:%.*]], i32 1, i1 false) ; CHECK-NEXT: br label [[BB:%.*]] ; CHECK: bb: ; CHECK-NEXT: ret void @@ -126,7 +126,7 @@ declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1) define void @test5(i8* %dest, i8* %src) { ; CHECK-LABEL: @test5( -; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i32(i8* [[DEST:%.*]], i8* [[SRC:%.*]], i32 1, i1 false) +; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i32(i8* nonnull [[DEST:%.*]], i8* nonnull [[SRC:%.*]], i32 1, i1 false) ; CHECK-NEXT: br label [[BB:%.*]] ; CHECK: bb: ; CHECK-NEXT: ret void @@ -159,7 +159,7 @@ declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i1) define void @test6(i8* %dest) { ; CHECK-LABEL: @test6( -; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* [[DEST:%.*]], i8 -1, i32 1, i1 false) +; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* nonnull [[DEST:%.*]], i8 -1, i32 1, i1 false) ; CHECK-NEXT: br label [[BB:%.*]] ; CHECK: bb: ; CHECK-NEXT: ret void Index: llvm/test/Transforms/JumpThreading/assume.ll =================================================================== --- llvm/test/Transforms/JumpThreading/assume.ll +++ llvm/test/Transforms/JumpThreading/assume.ll @@ -229,6 +229,31 @@ store atomic i32 0, i32* @g unordered, align 4 ret void } + +define void @can_fold_assume5(i32, i32, i1 zeroext) { +; CHECK-LABEL: can_fold_assume5 +; CHECK: @llvm.assume +; CHECK: @llvm.assume +; CHECK-NOT: br +; CHECK-NOT: @dummy(i1 true) +; CHECK-NEXT: ret void + %4 = icmp slt i32 %0, 234 + tail call void @llvm.assume(i1 %4) + %5 = icmp sgt i32 %1, 789 + tail call void @llvm.assume(i1 %5) + %6 = select i1 %2, i32 %0, i32 %1 + %7 = add i32 %6, -234 + %8 = icmp ult i32 %7, 556 + br i1 %8, label %label1, label %label2 + +label1: + tail call void @dummy(i1 true) + br label %label2 + +label2: + ret void +} + ; Function Attrs: nounwind declare void @llvm.assume(i1) #1