From: Sanjay Patel Date: Sat, 26 Nov 2016 15:23:20 +0000 (+0000) Subject: [InstCombine] don't drop metadata in FoldOpIntoSelect() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adc3b91adde2204bcd81b52dd0408737ea6c998f;p=llvm [InstCombine] don't drop metadata in FoldOpIntoSelect() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287980 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 2529c473554..cdbc8eb4585 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -819,9 +819,9 @@ Instruction *InstCombiner::FoldOpIntoSelect(Instruction &Op, SelectInst *SI) { } } - Value *SelectTVal = foldOperationIntoSelectOperand(Op, TV, this); - Value *SelectFVal = foldOperationIntoSelectOperand(Op, FV, this); - return SelectInst::Create(SI->getCondition(), SelectTVal, SelectFVal); + Value *NewTV = foldOperationIntoSelectOperand(Op, TV, this); + Value *NewFV = foldOperationIntoSelectOperand(Op, FV, this); + return SelectInst::Create(SI->getCondition(), NewTV, NewFV, "", nullptr, SI); } /// Given a binary operator, cast instruction, or select which has a PHI node as diff --git a/test/Transforms/InstCombine/select_meta.ll b/test/Transforms/InstCombine/select_meta.ll index 27c0c1c309c..82a85e5836d 100644 --- a/test/Transforms/InstCombine/select_meta.ll +++ b/test/Transforms/InstCombine/select_meta.ll @@ -17,6 +17,17 @@ define i32 @foo(i32) local_unnamed_addr #0 { ret i32 %5 } +define i8 @shrink_select(i1 %cond, i32 %x) { +; CHECK-LABEL: @shrink_select( +; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 %x to i8 +; CHECK-NEXT: [[TRUNC:%.*]] = select i1 %cond, i8 [[TMP1]], i8 42, !prof ![[MD1]] +; CHECK-NEXT: ret i8 [[TRUNC]] +; + %sel = select i1 %cond, i32 %x, i32 42, !prof !1 + %trunc = trunc i32 %sel to i8 + ret i8 %trunc +} + define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) { ; CHECK-LABEL: @min_max_bitcast( ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> %a, %b