1; If we have an 'and' of the result of an 'or', and one of the 'or' operands 2; cannot have contributed any of the resultant bits, delete the or. This 3; occurs for very common C/C++ code like this: 4; 5; struct foo { int A : 16; int B : 16; }; 6; void test(struct foo *F, int X, int Y) { 7; F->A = X; F->B = Y; 8; } 9; 10; Which corresponds to test1. 11; 12; This tests arbitrary precision integers. 13 14; RUN: opt < %s -instcombine -S | not grep "or " 15; END. 16 17define i17 @test1(i17 %X, i17 %Y) { 18 %A = and i17 %X, 7 19 %B = and i17 %Y, 8 20 %C = or i17 %A, %B 21 %D = and i17 %C, 7 ;; This cannot include any bits from %Y! 22 ret i17 %D 23} 24 25define i49 @test3(i49 %X, i49 %Y) { 26 %B = shl i49 %Y, 1 27 %C = or i49 %X, %B 28 %D = and i49 %C, 1 ;; This cannot include any bits from %Y! 29 ret i49 %D 30} 31 32define i67 @test4(i67 %X, i67 %Y) { 33 %B = lshr i67 %Y, 66 34 %C = or i67 %X, %B 35 %D = and i67 %C, 2 ;; This cannot include any bits from %Y! 36 ret i67 %D 37} 38 39define i231 @or_test1(i231 %X, i231 %Y) { 40 %A = and i231 %X, 1 41 %B = or i231 %A, 1 ;; This cannot include any bits from X! 42 ret i231 %B 43} 44 45define i7 @or_test2(i7 %X, i7 %Y) { 46 %A = shl i7 %X, 6 47 %B = or i7 %A, 64 ;; This cannot include any bits from X! 48 ret i7 %B 49} 50 51