[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/SignlessTypes/Makefile div.c

Reid Spencer reid at x10sys.com
Tue Oct 24 17:28:03 PDT 2006



Changes in directory llvm-test/SingleSource/UnitTests/SignlessTypes:

Makefile added (r1.1)
div.c added (r1.1)
---
Log message:

Add a unit test directory for testing basic operations affected by the
Signless Types feature. This unit tests are aimed at making sure that
various InstCombine transforms continue to work correctly after the
SignlessTypes feature is implemented.


---
Diffs of the changes:  (+63 -0)

 Makefile |    5 +++++
 div.c    |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)


Index: llvm-test/SingleSource/UnitTests/SignlessTypes/Makefile
diff -c /dev/null llvm-test/SingleSource/UnitTests/SignlessTypes/Makefile:1.1
*** /dev/null	Tue Oct 24 19:27:58 2006
--- llvm-test/SingleSource/UnitTests/SignlessTypes/Makefile	Tue Oct 24 19:27:48 2006
***************
*** 0 ****
--- 1,5 ----
+ # SingleSource/UnitTests/Vector/Makefile
+ LEVEL = ../../..
+ 
+ include $(LEVEL)/Makefile.config
+ include $(LEVEL)/SingleSource/Makefile.singlesrc


Index: llvm-test/SingleSource/UnitTests/SignlessTypes/div.c
diff -c /dev/null llvm-test/SingleSource/UnitTests/SignlessTypes/div.c:1.1
*** /dev/null	Tue Oct 24 19:28:03 2006
--- llvm-test/SingleSource/UnitTests/SignlessTypes/div.c	Tue Oct 24 19:27:48 2006
***************
*** 0 ****
--- 1,58 ----
+ /* 
+  * This file is used to test division operations in conjunction with
+  * the Signless Types feature. The DIV instruction was replaced with
+  * UDIV, SDIV and FDIV instructions. The tests here are aimed at
+  * triggering InstructionCombining transforms to exercise them and
+  * ensure they are not altering the computed values.
+  */
+ 
+ #include <stdio.h>
+ 
+ unsigned 
+ udivTest1(unsigned X, unsigned Y) {
+ 
+   unsigned Tally = 0;
+   /* 0 / X == 0 */
+   Tally += 0 / X;
+ 
+   /* div X, 1 == X */
+   Tally += X / 1;
+ 
+   /* div X, -1 == -X */
+   Tally += X / -1;
+ 
+   /* div X, (Cond ? 0 : Y) -> div X, Y.  */
+   Tally += ( X == Y ? 0 : Y );
+   Tally += ( X == Y ? ((unsigned)0) : Y );
+ 
+   /* div X, (Cond ? Y : 0) -> div X, Y */
+   Tally += ( X != Y ? Y : 0 );
+   Tally += ( X != Y ? Y : ((unsigned)0) );
+ 
+   /* (X / C1) / C2  -> X / (C1*C2) */
+   Tally += ( X / 2 ) / 4;
+   Tally += ( X / ((unsigned)2)) / ((unsigned)4);
+ 
+   /* X udiv C^2 -> X >> C */
+   Tally += X / 4;
+   Tally += X / ((unsigned)4);
+ 
+   /* X udiv (C1 << N), where C1 is "1<<C2"  -->  X >> (N+C2) */
+   Tally += X / (4 << Y);
+   Tally += X / (((unsigned)4) << Y);
+ 
+   /* udiv X, (Select Cond, C1, C2) --> Select Cond, (shr X, C1), (shr X, C2) */
+   Tally += X / (X == Y, 2, 4);
+   Tally += X / (X == Y, ((unsigned)2), ((unsigned)4));
+ 
+   /* -X/C -> X/-C */
+   Tally += -X / 2;
+   Tally += -X / ((unsigned)2);
+ 
+   return Tally;
+ }
+ 
+ int main(int argc, char**argv) {
+   unsigned result = udivTest1(42, 3);
+   printf("udivTest1(42,17) = %u\n", udivTest1(42,17));
+ }






More information about the llvm-commits mailing list