[InstCombine] Update predicate when canonicalizing comparisons in canonicalizeClampLike.
authorRicky Zhou <ricky+llvm@rzhou.org>
Tue, 26 Apr 2022 21:26:54 +0000 (17:26 -0400)
committerSanjay Patel <spatel@rotateright.com>
Tue, 26 Apr 2022 21:35:45 +0000 (17:35 -0400)
commit4041c44853588c1e4918ec4a160c053cf08432b5
treeffd88429c8eb53d237c6fd42c26b8f66562e12b5
parentff289feeba402a7cf68444e05e4ad2f1e5816767
[InstCombine] Update predicate when canonicalizing comparisons in canonicalizeClampLike.

canonicalizeClampLike canonicalizes the ule/ugt comparisons to ult/uge,
respectively. However, it does not update the variable holding the
comparison predicate type after doing this. Later code fails to handle
the non-canonical predicate type (specifically, the swap of
ThresholdLowIncl and ThresholdHighExcl when Pred0 has been canonicalized
from ugt to uge). This leads to the miscompile reported in PR53252. Fix
this by updating the comparison predicate after canonicalizing.

Fixes #53252

Differential Revision: https://reviews.llvm.org/D119690
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll