[llvm] r223923 - InstSimplify: [al]shr exact undef, %X -> undef

David Majnemer david.majnemer at gmail.com
Wed Dec 10 01:14:53 PST 2014


Author: majnemer
Date: Wed Dec 10 03:14:52 2014
New Revision: 223923

URL: http://llvm.org/viewvc/llvm-project?rev=223923&view=rev
Log:
InstSimplify: [al]shr exact undef, %X -> undef

Exact shifts always keep the non-zero bits of their input.  This means
it keeps it's undef bits.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/undef.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=223923&r1=223922&r2=223923&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Dec 10 03:14:52 2014
@@ -1387,8 +1387,10 @@ static Value *SimplifyLShrInst(Value *Op
       return V;
 
   // undef >>l X -> 0
+  // undef >>l X -> undef (if it's exact)
   if (match(Op0, m_Undef()))
-    return Constant::getNullValue(Op0->getType());
+    return isExact ? UndefValue::get(Op0->getType())
+                   : Constant::getNullValue(Op0->getType());
 
   // (X << A) >> A -> X
   Value *X;
@@ -1421,8 +1423,10 @@ static Value *SimplifyAShrInst(Value *Op
     return Op0;
 
   // undef >>a X -> all ones
+  // undef >>a X -> undef (if it's exact)
   if (match(Op0, m_Undef()))
-    return Constant::getAllOnesValue(Op0->getType());
+    return isExact ? UndefValue::get(Op0->getType())
+                   : Constant::getAllOnesValue(Op0->getType());
 
   // (X << A) >> A -> X
   Value *X;

Modified: llvm/trunk/test/Transforms/InstSimplify/undef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/undef.ll?rev=223923&r1=223922&r2=223923&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/undef.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/undef.ll Wed Dec 10 03:14:52 2014
@@ -174,3 +174,17 @@ define i32 @test21(i32 %a) {
   %b = sdiv i32 %a, 0
   ret i32 %b
 }
+
+; CHECK-LABEL: @test22
+; CHECK: ret i32 undef
+define i32 @test22(i32 %a) {
+  %b = ashr exact i32 undef, %a
+  ret i32 %b
+}
+
+; CHECK-LABEL: @test23
+; CHECK: ret i32 undef
+define i32 @test23(i32 %a) {
+  %b = lshr exact i32 undef, %a
+  ret i32 %b
+}





More information about the llvm-commits mailing list