* A & ~A == 0
* A / (2^c) == A >> c if unsigned
* 0 / A == 0
* 1.0 * A == A
* A * (2^c) == A << c
* A ^ ~A == -1
* A | ~A == -1
* 0 % X = 0
* A % (2^c) == A & (c-1) if unsigned
* A - (A & B) == A & ~B
* -1 - A == ~A
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5588
91177308-0d34-0410-b5e6-
96231b3b80d8
ret bool %B
}
+int %test7(int %A) { ; A & ~A == 0
+ %NotA = xor int %A, -1
+ %B = and int %A, %NotA
+ ret int %B
+}
\ No newline at end of file
%B = div int %A, 1
ret int %B
}
+
+uint %test2(uint %A) {
+ %B = div uint %A, 8 ; => Shift
+ ret int %B
+}
+
+int %test3(int %A) {
+ %B = div int 0, %A ; => 0, don't need to keep traps
+ ret int %B
+}
ret int %B
end
+double %test4(double %A) {
+ %B = mul double 1.0, %A ; This is safe for FP
+ ret double %B
+}
+
+int %test5(int %A) {
+ %B = mul int %A, 8
+ ret int %B
+}
ret int %B
}
+int %test11(int %A) { ; A ^ ~A == -1
+ %NotA = xor int -1, %A
+ %B = xor int %A, %NotA
+ ret int %B
+}
+
+int %test12(int %A) { ; A | ~A == -1
+ %NotA = xor int -1, %A
+ %B = or int %A, %NotA
+ ret int %B
+}
implementation
-int "test1"(int %A) {
+int %test1(int %A) {
%B = rem int %A, 1 ; ISA constant 0
ret int %B
}
+int %test2(int %A) { ; 0 % X = 0, we don't need ot preserve traps
+ %B = rem int 0, %A
+ ret int %B
+}
+
+uint %test3(uint %A) {
+ %B = rem uint %A, 8 ; & 7
+ ret uint %B
+}
%E = sub int %A, %D
ret int %E
}
+
+int %test6(int %A, int %B) {
+ %C = and int %A, %B ; A - (A & B) => A & ~B
+ %D = sub int %A, %C
+ ret int %D
+}
+
+int %test7(int %A) {
+ %B = sub int -1, %A ; B = ~A
+ ret int %B
+}
+