diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -1313,9 +1313,10 @@ IV, &CB, ValueLatticeElement::getRange(NewCR, /*MayIncludeUndef*/ false)); return; - } else if (Pred == CmpInst::ICMP_EQ && CondVal.isConstant()) { + } else if (Pred == CmpInst::ICMP_EQ && + (CondVal.isConstant() || CondVal.isNotConstant())) { // For non-integer values or integer constant expressions, only - // propagate equal constants. + // propagate equal constants or not-constants. addAdditionalUser(OtherOp, &CB); mergeInValue(IV, &CB, CondVal); return; diff --git a/llvm/test/Transforms/SCCP/conditions-ranges.ll b/llvm/test/Transforms/SCCP/conditions-ranges.ll --- a/llvm/test/Transforms/SCCP/conditions-ranges.ll +++ b/llvm/test/Transforms/SCCP/conditions-ranges.ll @@ -1370,6 +1370,69 @@ ret void } +define i32 @equal_not_constant(ptr noundef %p, ptr noundef %q) { +; CHECK-LABEL: @equal_not_constant( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P:%.*]], null +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]] +; CHECK: if.then: +; CHECK-NEXT: [[CMP_THEN:%.*]] = icmp eq ptr [[P]], [[Q:%.*]] +; CHECK-NEXT: br i1 [[CMP_THEN]], label [[IF_THEN1:%.*]], label [[IF_END]] +; CHECK: if.then1: +; CHECK-NEXT: call void @use(i1 true) +; CHECK-NEXT: br label [[IF_END]] +; CHECK: if.end: +; CHECK-NEXT: ret i32 0 +; +entry: + %cmp = icmp ne ptr %p, null + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %cmp.then = icmp eq ptr %p, %q + br i1 %cmp.then, label %if.then1, label %if.end + +if.then1: ; preds = %if.then + %cmp.then1 = icmp ne ptr %q, null + call void @use(i1 %cmp.then1) + br label %if.end + +if.end: + ret i32 0 +} + +define i32 @not_equal_not_constant(ptr noundef %p, ptr noundef %q) { +; CHECK-LABEL: @not_equal_not_constant( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P:%.*]], null +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]] +; CHECK: if.then: +; CHECK-NEXT: [[CMP_THEN:%.*]] = icmp ne ptr [[P]], [[Q:%.*]] +; CHECK-NEXT: br i1 [[CMP_THEN]], label [[IF_THEN1:%.*]], label [[IF_END]] +; CHECK: if.then1: +; CHECK-NEXT: [[CMP_THEN1:%.*]] = icmp ne ptr [[Q]], null +; CHECK-NEXT: call void @use(i1 [[CMP_THEN1]]) +; CHECK-NEXT: br label [[IF_END]] +; CHECK: if.end: +; CHECK-NEXT: ret i32 0 +; +entry: + %cmp = icmp ne ptr %p, null + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %cmp.then = icmp ne ptr %p, %q + br i1 %cmp.then, label %if.then1, label %if.end + +if.then1: ; preds = %if.then + %cmp.then1 = icmp ne ptr %q, null + call void @use(i1 %cmp.then1) + br label %if.end + +if.end: + ret i32 0 +} + define i1 @ptr_icmp_data_layout() { ; CHECK-LABEL: @ptr_icmp_data_layout( ; CHECK-NEXT: ret i1 false