[PATCH] D155461: [InstCombine] Keep !unpredictable when combining select+add

Paweł Bylica via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 07:08:23 PDT 2023


chfast created this revision.
chfast added a reviewer: spatel.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
chfast requested review of this revision.
Herald added a project: LLVM.

Fixes https://github.com/llvm/llvm-project/issues/63910


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155461

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/unpredictable-select.ll


Index: llvm/test/Transforms/InstCombine/unpredictable-select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/unpredictable-select.ll
+++ llvm/test/Transforms/InstCombine/unpredictable-select.ll
@@ -3,7 +3,7 @@
 
 define i64 @add_select(i1 %cond, i64 %x, i64 %y) {
 ; CHECK-LABEL: @add_select(
-; CHECK-NEXT:    [[ADD:%.*]] = select i1 [[COND:%.*]], i64 [[Y:%.*]], i64 0
+; CHECK-NEXT:    [[ADD:%.*]] = select i1 [[COND:%.*]], i64 [[Y:%.*]], i64 0, !unpredictable [[META0:![0-9]+]]
 ; CHECK-NEXT:    [[RET:%.*]] = add i64 [[ADD]], [[X:%.*]]
 ; CHECK-NEXT:    ret i64 [[RET]]
 ;
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -537,7 +537,7 @@
     if (!isa<Constant>(OOp) ||
         (OOpIsAPInt && isSelect01(C->getUniqueInteger(), *OOpC))) {
       Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp,
-                                           Swapped ? OOp : C);
+                                           Swapped ? OOp : C, "", &SI);
       if (isa<FPMathOperator>(&SI))
         cast<Instruction>(NewSel)->setFastMathFlags(FMF);
       NewSel->takeName(TVI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155461.541012.patch
Type: text/x-patch
Size: 1348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/dbfb4942/attachment.bin>


More information about the llvm-commits mailing list