[llvm-commits] [llvm] r124081 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/fold.ll

Nick Lewycky nicholas at mxc.ca
Sun Jan 23 12:06:05 PST 2011


Author: nicholas
Date: Sun Jan 23 14:06:05 2011
New Revision: 124081

URL: http://llvm.org/viewvc/llvm-project?rev=124081&view=rev
Log:
Simplify some code with no functionality change. Make the test a lot more
robust against smarter optimizations, using the power of FileCheck.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp
    llvm/trunk/test/Analysis/ScalarEvolution/fold.ll

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=124081&r1=124080&r2=124081&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sun Jan 23 14:06:05 2011
@@ -904,15 +904,11 @@
     // so, we should be able to simplify this further.
     const SCEV *X = ST->getOperand();
     ConstantRange CR = getUnsignedRange(X);
-    unsigned OrigBits = CR.getBitWidth();
     unsigned TruncBits = getTypeSizeInBits(ST->getType());
     unsigned NewBits = getTypeSizeInBits(Ty);
     if (CR.truncate(TruncBits).zeroExtend(NewBits).contains(
-            CR.zextOrTrunc(NewBits))) {
-      if (NewBits > OrigBits) return getZeroExtendExpr(X, Ty);
-      if (NewBits < OrigBits) return getTruncateExpr(X, Ty);
-      return X;
-    }
+            CR.zextOrTrunc(NewBits)))
+      return getTruncateOrZeroExtend(X, Ty);
   }
 
   // If the input value is a chrec scev, and we can prove that the value
@@ -1062,15 +1058,11 @@
     // so, we should be able to simplify this further.
     const SCEV *X = ST->getOperand();
     ConstantRange CR = getSignedRange(X);
-    unsigned OrigBits = CR.getBitWidth();
     unsigned TruncBits = getTypeSizeInBits(ST->getType());
     unsigned NewBits = getTypeSizeInBits(Ty);
     if (CR.truncate(TruncBits).signExtend(NewBits).contains(
-            CR.sextOrTrunc(NewBits))) {
-      if (NewBits > OrigBits) return getSignExtendExpr(X, Ty);
-      if (NewBits < OrigBits) return getTruncateExpr(X, Ty);
-      return X;
-    }
+            CR.sextOrTrunc(NewBits)))
+      return getTruncateOrSignExtend(X, Ty);
   }
 
   // If the input value is a chrec scev, and we can prove that the value

Modified: llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/fold.ll?rev=124081&r1=124080&r2=124081&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/fold.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/fold.ll Sun Jan 23 14:06:05 2011
@@ -23,36 +23,40 @@
   ret i8 %C
 }
 
-define void @test4(i32 %x) {
+define void @test4(i32 %x, i32 %y) {
 entry:
-  %0 = icmp sge i32 %x, 0
-  br i1 %0, label %loop, label %exit
+  %Y = and i32 %y, 3
+  br label %loop
 loop:
   %A = phi i32 [0, %entry], [%I, %loop]
-  %rand = icmp sgt i32 %A, 10
-  %Z = select i1 %rand, i32 %A, i32 10
-  %B = trunc i32 %Z to i16
+  %rand1 = icmp sgt i32 %A, %Y
+  %Z1 = select i1 %rand1, i32 %A, i32 %Y
+  %rand2 = icmp ugt i32 %A, %Z1
+  %Z2 = select i1 %rand2, i32 %A, i32 %Z1
+; CHECK: %Z2 =
+; CHECK-NEXT: -->  ([[EXPR:.*]]){{ +}}Exits: 20
+  %B = trunc i32 %Z2 to i16
   %C = sext i16 %B to i30
 ; CHECK: %C =
-; CHECK-NEXT: (trunc i32 (10 smax {0,+,1}<%loop>) to i30)
+; CHECK-NEXT: (trunc i32 ([[EXPR]]) to i30)
   %D = sext i16 %B to i32
 ; CHECK: %D =
-; CHECK-NEXT: (10 smax {0,+,1}<%loop>)
+; CHECK-NEXT: ([[EXPR]])
   %E = sext i16 %B to i34
 ; CHECK: %E =
-; CHECK-NEXT: (zext i32 (10 smax {0,+,1}<%loop>) to i34)
+; CHECK-NEXT: (zext i32 ([[EXPR]]) to i34)
   %F = zext i16 %B to i30
 ; CHECK: %F =
-; CHECK-NEXT: (trunc i32 (10 smax {0,+,1}<%loop>) to i30
+; CHECK-NEXT: (trunc i32 ([[EXPR]]) to i30
   %G = zext i16 %B to i32
 ; CHECK: %G =
-; CHECK-NEXT: (10 smax {0,+,1}<%loop>)
+; CHECK-NEXT: ([[EXPR]])
   %H = zext i16 %B to i34
 ; CHECK: %H =
-; CHECK-NEXT: (zext i32 (10 smax {0,+,1}<%loop>) to i34)
+; CHECK-NEXT: (zext i32 ([[EXPR]]) to i34)
   %I = add i32 %A, 1
-  %1 = icmp ne i32 %A, 20
-  br i1 %1, label %loop, label %exit
+  %0 = icmp ne i32 %A, 20
+  br i1 %0, label %loop, label %exit
 exit:
   ret void
-}
\ No newline at end of file
+}





More information about the llvm-commits mailing list