From 679b18fd6ab9b0d19bbafd4192799aa8a1c76725 Mon Sep 17 00:00:00 2001 From: Michael Berg Date: Mon, 20 Aug 2018 22:26:58 +0000 Subject: [PATCH] extend binop folds for selects to include true and false binops flag intersection Summary: This change address bug 38641 Reviewers: spatel, wristow Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D50996 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340222 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineSelect.cpp | 3 ++- test/Transforms/InstCombine/select_meta.ll | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineSelect.cpp b/lib/Transforms/InstCombine/InstCombineSelect.cpp index 04fa2f95182..f09a67d96f3 100644 --- a/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -355,7 +355,8 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI, Value *Op1 = MatchIsOpZero ? NewSI : MatchOp; if (auto *BO = dyn_cast(TI)) { BinaryOperator *NewBO = BinaryOperator::Create(BO->getOpcode(), Op0, Op1); - NewBO->copyIRFlags(BO); + NewBO->copyIRFlags(TI); + NewBO->andIRFlags(FI); return NewBO; } if (auto *TGEP = dyn_cast(TI)) { diff --git a/test/Transforms/InstCombine/select_meta.ll b/test/Transforms/InstCombine/select_meta.ll index 28caac45f96..76a4ea943b5 100644 --- a/test/Transforms/InstCombine/select_meta.ll +++ b/test/Transforms/InstCombine/select_meta.ll @@ -7,12 +7,12 @@ define i32 @foo(i32) local_unnamed_addr #0 { ; CHECK-LABEL: @foo( ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %0, 2 ; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof ![[$MD1:[0-9]+]] -; CHECK-NEXT: [[TMP3:%.*]] = add nsw i32 [[DOTV]], %0 +; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[DOTV]], %0 ; CHECK-NEXT: ret i32 [[TMP3]] ; %2 = icmp sgt i32 %0, 2 %3 = add nsw i32 %0, 20 - %4 = add nsw i32 %0, -20 + %4 = add i32 %0, -20 select i1 %2, i32 %3, i32 %4, !prof !1 ret i32 %5 } -- 2.11.0