51 lines · plain
1; If we have an 'and' of the result of an 'or', and one of the 'or' operands2; cannot have contributed any of the resultant bits, delete the or. This3; 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 -passes=instcombine -S | not grep "or "15; END.16 17define i17 @test1(i17 %X, i17 %Y) {18 %A = and i17 %X, 719 %B = and i17 %Y, 820 %C = or i17 %A, %B21 %D = and i17 %C, 7 ;; This cannot include any bits from %Y!22 ret i17 %D23}24 25define i49 @test3(i49 %X, i49 %Y) {26 %B = shl i49 %Y, 127 %C = or i49 %X, %B28 %D = and i49 %C, 1 ;; This cannot include any bits from %Y!29 ret i49 %D30}31 32define i67 @test4(i67 %X, i67 %Y) {33 %B = lshr i67 %Y, 6634 %C = or i67 %X, %B35 %D = and i67 %C, 2 ;; This cannot include any bits from %Y!36 ret i67 %D37}38 39define i231 @or_test1(i231 %X, i231 %Y) {40 %A = and i231 %X, 141 %B = or i231 %A, 1 ;; This cannot include any bits from X!42 ret i231 %B43}44 45define i7 @or_test2(i7 %X, i7 %Y) {46 %A = shl i7 %X, 647 %B = or i7 %A, 64 ;; This cannot include any bits from X!48 ret i7 %B49}50 51