Index: lib/Transforms/InstCombine/InstCombineAddSub.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1200,12 +1200,13 @@ return BinaryOperator::CreateAnd(NewAdd, C2); } } + } - // Try to fold constant add into select arguments. + // Try to fold constant add into select arguments. + if (isa(RHS)) if (SelectInst *SI = dyn_cast(LHS)) if (Instruction *R = FoldOpIntoSelect(I, SI)) return R; - } // add (select X 0 (sub n A)) A --> select X A n { Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1403,10 +1403,11 @@ return BinaryOperator::CreateAnd(NewCast, C3); } } + } + if (isa(Op1)) if (Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I)) return FoldedLogic; - } if (Instruction *DeMorgan = matchDeMorgansLaws(I, Builder)) return DeMorgan; @@ -2141,10 +2142,11 @@ return BinaryOperator::CreateXor(Or, Builder->getInt(C1->getValue() & ~RHS->getValue())); } + } + if (isa(Op1)) if (Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I)) return FoldedLogic; - } // Given an OR instruction, check to see if this is a bswap. if (Instruction *BSwap = MatchBSwap(I)) @@ -2604,10 +2606,11 @@ } } } + } + if (isa(Op1)) if (Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I)) return FoldedLogic; - } BinaryOperator *Op1I = dyn_cast(Op1); if (Op1I) { Index: test/Transforms/InstCombine/add.ll =================================================================== --- test/Transforms/InstCombine/add.ll +++ test/Transforms/InstCombine/add.ll @@ -246,8 +246,7 @@ define <2 x i32> @test19vec(i1 %C) { ; CHECK-LABEL: @test19vec( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> -; CHECK-NEXT: [[V:%.*]] = add nuw nsw <2 x i32> [[A]], +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> , <2 x i32> Index: test/Transforms/InstCombine/or.ll =================================================================== --- test/Transforms/InstCombine/or.ll +++ test/Transforms/InstCombine/or.ll @@ -714,8 +714,7 @@ define <2 x i32> @test49vec(i1 %C) { ; CHECK-LABEL: @test49vec( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> zeroinitializer -; CHECK-NEXT: [[V:%.*]] = or <2 x i32> [[A]], +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> , <2 x i32> Index: test/Transforms/InstCombine/xor.ll =================================================================== --- test/Transforms/InstCombine/xor.ll +++ test/Transforms/InstCombine/xor.ll @@ -365,8 +365,7 @@ define <2 x i32> @test29vec(i1 %C) { ; CHECK-LABEL: @test29vec( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> -; CHECK-NEXT: [[V:%.*]] = xor <2 x i32> [[A]], +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> , <2 x i32> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> , <2 x i32>