[llvm] 4d05d84 - Revert "[InstSimplify] Support all instructions in simplifyWithOpReplaced()"

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 07:52:03 PDT 2023


Author: Nikita Popov
Date: 2023-04-24T16:51:54+02:00
New Revision: 4d05d846ec7b006d1aa850d359f64997e52e7fd2

URL: https://github.com/llvm/llvm-project/commit/4d05d846ec7b006d1aa850d359f64997e52e7fd2
DIFF: https://github.com/llvm/llvm-project/commit/4d05d846ec7b006d1aa850d359f64997e52e7fd2.diff

LOG: Revert "[InstSimplify] Support all instructions in simplifyWithOpReplaced()"

This reverts commit 3e3e41b263f4aa76a5a36f02727827bebccdbf07.

This appears to cause a stage2 miscompile of llvm-profgen.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/select-maxmin.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ab0c33ca9cc7..0097c618eaa5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -74,10 +74,6 @@ static Value *simplifyGEPInst(Type *, Value *, ArrayRef<Value *>, bool,
                               const SimplifyQuery &, unsigned);
 static Value *simplifySelectInst(Value *, Value *, Value *,
                                  const SimplifyQuery &, unsigned);
-static Value *simplifyInstructionWithOperands(Instruction *I,
-                                              ArrayRef<Value *> NewOps,
-                                              const SimplifyQuery &SQ,
-                                              unsigned MaxRecurse);
 
 static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
                                      Value *FalseVal) {
@@ -4274,8 +4270,23 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
       return Simplified != V ? Simplified : nullptr;
     };
 
-    return PreventSelfSimplify(
-        ::simplifyInstructionWithOperands(I, NewOps, Q, MaxRecurse - 1));
+    if (auto *B = dyn_cast<BinaryOperator>(I))
+      return PreventSelfSimplify(simplifyBinOp(B->getOpcode(), NewOps[0],
+                                               NewOps[1], Q, MaxRecurse - 1));
+
+    if (CmpInst *C = dyn_cast<CmpInst>(I))
+      return PreventSelfSimplify(simplifyCmpInst(C->getPredicate(), NewOps[0],
+                                                 NewOps[1], Q, MaxRecurse - 1));
+
+    if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
+      return PreventSelfSimplify(simplifyGEPInst(
+          GEP->getSourceElementType(), NewOps[0], ArrayRef(NewOps).slice(1),
+          GEP->isInBounds(), Q, MaxRecurse - 1));
+
+    if (isa<SelectInst>(I))
+      return PreventSelfSimplify(simplifySelectInst(
+          NewOps[0], NewOps[1], NewOps[2], Q, MaxRecurse - 1));
+    // TODO: We could hand off more cases to instsimplify here.
   }
 
   // If all operands are constant after substituting Op for RepOp then we can

diff  --git a/llvm/test/Transforms/InstSimplify/select-maxmin.ll b/llvm/test/Transforms/InstSimplify/select-maxmin.ll
index 68d16c8eeb79..34a3203908e6 100644
--- a/llvm/test/Transforms/InstSimplify/select-maxmin.ll
+++ b/llvm/test/Transforms/InstSimplify/select-maxmin.ll
@@ -2136,7 +2136,10 @@ define <4 x i8> @ult_yx_umax_select_y_shuf_mask_fval(<4 x i8> %x, <4 x i8> %y) {
 
 define i8 @select_umin_with_icmp_zero(i8 %x, i8 %y) {
 ; CHECK-LABEL: @select_umin_with_icmp_zero(
-; CHECK-NEXT:    ret i8 0
+; CHECK-NEXT:    [[MIN:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[MIN]], i8 0
+; CHECK-NEXT:    ret i8 [[SEL]]
 ;
   %min = call i8 @llvm.umin.i8(i8 %x, i8 %y)
   %cmp = icmp eq i8 %x, 0


        


More information about the llvm-commits mailing list