From 40a2e35599b5e5fa0dd93ac4edf4bf02ee636f6e Mon Sep 17 00:00:00 2001 From: Juneyoung Lee Date: Tue, 26 Apr 2022 09:57:25 +0900 Subject: [PATCH] [InstCombine] Remove the undef-related workaround code in visitSelectInst 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 --- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 16 ---------------- llvm/test/Transforms/InstCombine/select-cmp.ll | 3 +-- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index e1f9c09..fce9a73 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -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(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); diff --git a/llvm/test/Transforms/InstCombine/select-cmp.ll b/llvm/test/Transforms/InstCombine/select-cmp.ll index dd39a78..2bd4fa9 100644 --- a/llvm/test/Transforms/InstCombine/select-cmp.ll +++ b/llvm/test/Transforms/InstCombine/select-cmp.ll @@ -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 -- 2.7.4