Skip to content

Commit

Permalink
[InstCombine] Remove the undef-related workaround code in visitSelect…
Browse files Browse the repository at this point in the history
…Inst

This patch removes an old hack in visitSelectInst that was written to avoid miscompilation bugs in loop unswitch.
(Added via https://reviews.llvm.org/D35811)

The legacy loop unswitch pass will be removed after D124376, and the new simple loop unswitch pass correctly uses freeze to avoid introducing UB after D124252.

Since the hack is not necessary anymore, this patch removes it.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D124426
  • Loading branch information
aqjune authored and Juneyoung Lee committed Apr 30, 2022
1 parent 112e3d8 commit 40a2e35
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
16 changes: 0 additions & 16 deletions llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Expand Up @@ -2644,22 +2644,6 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
Value *FalseVal = SI.getFalseValue();
Type *SelType = SI.getType();

// FIXME: Remove this workaround when freeze related patches are done.
// For select with undef operand which feeds into an equality comparison,
// don't simplify it so loop unswitch can know the equality comparison
// may have an undef operand. This is a workaround for PR31652 caused by
// descrepancy about branch on undef between LoopUnswitch and GVN.
if (match(TrueVal, m_Undef()) || match(FalseVal, m_Undef())) {
if (llvm::any_of(SI.users(), [&](User *U) {
ICmpInst *CI = dyn_cast<ICmpInst>(U);
if (CI && CI->isEquality())
return true;
return false;
})) {
return nullptr;
}
}

if (Value *V = SimplifySelectInst(CondVal, TrueVal, FalseVal,
SQ.getWithInstruction(&SI)))
return replaceInstUsesWith(SI, V);
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstCombine/select-cmp.ll
Expand Up @@ -3,8 +3,7 @@

define i1 @f(i1 %cond, i32 %x, i32 %x2) {
; CHECK-LABEL: @f(
; CHECK-NEXT: [[Y:%.*]] = select i1 [[COND:%.*]], i32 poison, i32 [[X:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[Y]], [[X2:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[X2:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%y = select i1 %cond, i32 poison, i32 %x
Expand Down

0 comments on commit 40a2e35

Please sign in to comment.