Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -3708,6 +3708,16 @@ simplifySelectWithICmpCond(CondVal, TrueVal, FalseVal, Q, MaxRecurse)) return V; + // If we can compute the condition, there's no need for a select. + if (CondVal->getType()->getPrimitiveSizeInBits() == 1) { + APInt KnownOne(1, 0), KnownZero(1, 0); + computeKnownBits(CondVal, KnownZero, KnownOne, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); + if (KnownOne == 1) + return TrueVal; + if (KnownZero == 1) + return FalseVal; + } + return nullptr; } Index: test/Transforms/InstSimplify/select.ll =================================================================== --- test/Transforms/InstSimplify/select.ll +++ test/Transforms/InstSimplify/select.ll @@ -402,15 +402,14 @@ ret i32* %sel } -; FIXME: If the condition is known, we don't need to select. +; If the condition is known, we don't need to select. declare void @llvm.assume(i1) define i8 @assume_sel_cond(i1 %cond, i8 %x, i8 %y) { ; CHECK-LABEL: @assume_sel_cond( ; CHECK-NEXT: call void @llvm.assume(i1 %cond) -; CHECK-NEXT: [[SEL:%.*]] = select i1 %cond, i8 %x, i8 %y -; CHECK-NEXT: ret i8 [[SEL]] +; CHECK-NEXT: ret i8 %x ; call void @llvm.assume(i1 %cond) %sel = select i1 %cond, i8 %x, i8 %y @@ -421,8 +420,7 @@ ; CHECK-LABEL: @do_not_assume_sel_cond( ; CHECK-NEXT: [[NOTCOND:%.*]] = icmp eq i1 %cond, false ; CHECK-NEXT: call void @llvm.assume(i1 [[NOTCOND]]) -; CHECK-NEXT: [[SEL:%.*]] = select i1 %cond, i8 %x, i8 %y -; CHECK-NEXT: ret i8 [[SEL]] +; CHECK-NEXT: ret i8 %y ; %notcond = icmp eq i1 %cond, false call void @llvm.assume(i1 %notcond)