[llvm-branch-commits] [llvm] 40a2e35 - [InstCombine] Remove the undef-related workaround code in visitSelectInst

Juneyoung Lee via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Apr 30 04:51:50 PDT 2022


Author: Juneyoung Lee
Date: 2022-04-30T20:48:42+09:00
New Revision: 40a2e35599b5e5fa0dd93ac4edf4bf02ee636f6e

URL: https://github.com/llvm/llvm-project/commit/40a2e35599b5e5fa0dd93ac4edf4bf02ee636f6e
DIFF: https://github.com/llvm/llvm-project/commit/40a2e35599b5e5fa0dd93ac4edf4bf02ee636f6e.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    llvm/test/Transforms/InstCombine/select-cmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index e1f9c099d79fc..fce9a73d17e7a 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<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);

diff  --git a/llvm/test/Transforms/InstCombine/select-cmp.ll b/llvm/test/Transforms/InstCombine/select-cmp.ll
index dd39a78a9029c..2bd4fa9b47156 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


        


More information about the llvm-branch-commits mailing list