Skip to content

Commit 06b0426

Browse files
committed
[InstCombine] Add pre-commit tests for PR76554. NFC.
1 parent a085402 commit 06b0426

File tree

1 file changed

+117
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+117
-0
lines changed

llvm/test/Transforms/InstCombine/or.ll

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,3 +1777,120 @@ if.then:
17771777
if.else:
17781778
ret i32 0
17791779
}
1780+
1781+
; Tests from PR76554
1782+
define i32 @test_or_and_xor_constant(i32 %x, i32 %y) {
1783+
; CHECK-LABEL: @test_or_and_xor_constant(
1784+
; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], -2147483648
1785+
; CHECK-NEXT: [[B:%.*]] = xor i32 [[A]], -2147483648
1786+
; CHECK-NEXT: [[C:%.*]] = and i32 [[B]], [[Y:%.*]]
1787+
; CHECK-NEXT: [[D:%.*]] = or i32 [[C]], [[A]]
1788+
; CHECK-NEXT: ret i32 [[D]]
1789+
;
1790+
%a = and i32 %x, -2147483648
1791+
%b = xor i32 %a, -2147483648
1792+
%c = and i32 %b, %y
1793+
%d = or i32 %c, %a
1794+
ret i32 %d
1795+
}
1796+
1797+
define i32 @test_or_and_xor(i32 %a, i32 %b, i32 %c) {
1798+
; CHECK-LABEL: @test_or_and_xor(
1799+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
1800+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1801+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[A]]
1802+
; CHECK-NEXT: ret i32 [[OR]]
1803+
;
1804+
%xor = xor i32 %a, %b
1805+
%and = and i32 %xor, %c
1806+
%or = or i32 %and, %a
1807+
ret i32 %or
1808+
}
1809+
1810+
define i32 @test_or_and_xor_commuted1(i32 %a, i32 %b, i32 %c) {
1811+
; CHECK-LABEL: @test_or_and_xor_commuted1(
1812+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
1813+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1814+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[A]]
1815+
; CHECK-NEXT: ret i32 [[OR]]
1816+
;
1817+
%xor = xor i32 %b, %a
1818+
%and = and i32 %xor, %c
1819+
%or = or i32 %and, %a
1820+
ret i32 %or
1821+
}
1822+
1823+
define i32 @test_or_and_xor_commuted2(i32 %a, i32 %b, i32 %c) {
1824+
; CHECK-LABEL: @test_or_and_xor_commuted2(
1825+
; CHECK-NEXT: [[CC:%.*]] = mul i32 [[C:%.*]], [[C]]
1826+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
1827+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[CC]], [[XOR]]
1828+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[A]]
1829+
; CHECK-NEXT: ret i32 [[OR]]
1830+
;
1831+
%cc = mul i32 %c, %c
1832+
%xor = xor i32 %a, %b
1833+
%and = and i32 %cc, %xor
1834+
%or = or i32 %and, %a
1835+
ret i32 %or
1836+
}
1837+
1838+
define i32 @test_or_and_xor_commuted3(i32 %a, i32 %b, i32 %c) {
1839+
; CHECK-LABEL: @test_or_and_xor_commuted3(
1840+
; CHECK-NEXT: [[AA:%.*]] = mul i32 [[A:%.*]], [[A]]
1841+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AA]], [[B:%.*]]
1842+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1843+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AA]], [[AND]]
1844+
; CHECK-NEXT: ret i32 [[OR]]
1845+
;
1846+
%aa = mul i32 %a, %a
1847+
%xor = xor i32 %aa, %b
1848+
%and = and i32 %xor, %c
1849+
%or = or i32 %aa, %and
1850+
ret i32 %or
1851+
}
1852+
1853+
define i32 @test_or_and_xor_multiuse1(i32 %a, i32 %b, i32 %c) {
1854+
; CHECK-LABEL: @test_or_and_xor_multiuse1(
1855+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
1856+
; CHECK-NEXT: call void @use(i32 [[XOR]])
1857+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1858+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[A]]
1859+
; CHECK-NEXT: ret i32 [[OR]]
1860+
;
1861+
%xor = xor i32 %a, %b
1862+
call void @use(i32 %xor)
1863+
%and = and i32 %xor, %c
1864+
%or = or i32 %and, %a
1865+
ret i32 %or
1866+
}
1867+
1868+
; Negative tests
1869+
1870+
define i32 @test_or_and_xor_mismatched_op(i32 %a, i32 %b, i32 %c, i32 %d) {
1871+
; CHECK-LABEL: @test_or_and_xor_mismatched_op(
1872+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
1873+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1874+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[D:%.*]]
1875+
; CHECK-NEXT: ret i32 [[OR]]
1876+
;
1877+
%xor = xor i32 %a, %b
1878+
%and = and i32 %xor, %c
1879+
%or = or i32 %and, %d
1880+
ret i32 %or
1881+
}
1882+
1883+
define i32 @test_or_and_xor_multiuse2(i32 %a, i32 %b, i32 %c) {
1884+
; CHECK-LABEL: @test_or_and_xor_multiuse2(
1885+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
1886+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[C:%.*]]
1887+
; CHECK-NEXT: call void @use(i32 [[AND]])
1888+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[A]]
1889+
; CHECK-NEXT: ret i32 [[OR]]
1890+
;
1891+
%xor = xor i32 %a, %b
1892+
%and = and i32 %xor, %c
1893+
call void @use(i32 %and)
1894+
%or = or i32 %and, %a
1895+
ret i32 %or
1896+
}

0 commit comments

Comments
 (0)