diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1336,6 +1336,7 @@ ICmpInst::Predicate::ICMP_NE, APInt::getAllOnes(C0->getType()->getScalarSizeInBits())))) return nullptr; // Can't do, have all-ones element[s]. + Pred0 = ICmpInst::getFlippedStrictnessPredicate(Pred0); C0 = InstCombiner::AddOne(C0); break; default: @@ -1401,6 +1402,7 @@ case ICmpInst::Predicate::ICMP_SGE: // Also non-canonical, but here we don't need to change C2, // so we don't have any restrictions on C2, so we can just handle it. + Pred1 = ICmpInst::Predicate::ICMP_SLT; std::swap(ReplacementLow, ReplacementHigh); break; default: diff --git a/llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll b/llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll --- a/llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll @@ -187,12 +187,11 @@ } define i32 @n10_ugt_slt(i32 %x, i32 %replacement_low, i32 %replacement_high) { -; FIXME: This is incorrect, see PR53252. ; CHECK-LABEL: @n10_ugt_slt( -; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 0 -; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[X]], 128 -; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i32 [[REPLACEMENT_LOW:%.*]], i32 [[X]] -; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP2]], i32 [[REPLACEMENT_HIGH:%.*]], i32 [[TMP3]] +; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 [[REPLACEMENT_LOW:%.*]], i32 [[REPLACEMENT_HIGH:%.*]] +; CHECK-NEXT: [[T2:%.*]] = icmp ugt i32 [[X]], 128 +; CHECK-NEXT: [[R:%.*]] = select i1 [[T2]], i32 [[X]], i32 [[T1]] ; CHECK-NEXT: ret i32 [[R]] ; %t0 = icmp slt i32 %x, 0