[llvm] r347332 - [InstSimplify] fold funnel shifts with undef operands

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 20 09:35:00 PST 2018


Author: spatel
Date: Tue Nov 20 09:34:59 2018
New Revision: 347332

URL: http://llvm.org/viewvc/llvm-project?rev=347332&view=rev
Log:
[InstSimplify] fold funnel shifts with undef operands

Splitting these off from the D54666.

Patch by: nikic (Nikita Popov)

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

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=347332&r1=347331&r2=347332&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Nov 20 09:34:59 2018
@@ -5042,7 +5042,16 @@ static Value *simplifyIntrinsic(Function
   }
   case Intrinsic::fshl:
   case Intrinsic::fshr: {
-    Value *ShAmtArg = ArgBegin[2];
+    Value *Op0 = ArgBegin[0], *Op1 = ArgBegin[1], *ShAmtArg = ArgBegin[2];
+
+    // If both operands are undef, the result is undef.
+    if (match(Op0, m_Undef()) && match(Op1, m_Undef()))
+      return UndefValue::get(F->getReturnType());
+
+    // If shift amount is undef, assume it is zero.
+    if (match(ShAmtArg, m_Undef()))
+      return ArgBegin[IID == Intrinsic::fshl ? 0 : 1];
+
     const APInt *ShAmtC;
     if (match(ShAmtArg, m_APInt(ShAmtC))) {
       // If there's effectively no shift, return the 1st arg or 2nd arg.

Modified: llvm/trunk/test/Transforms/InstSimplify/call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/call.ll?rev=347332&r1=347331&r2=347332&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/call.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/call.ll Tue Nov 20 09:34:59 2018
@@ -632,8 +632,7 @@ define <2 x i8> @fshr_zero_shift_guard_s
 
 define i8 @fshl_ops_undef(i8 %shamt) {
 ; CHECK-LABEL: @fshl_ops_undef(
-; CHECK-NEXT:    [[R:%.*]] = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 [[SHAMT:%.*]])
-; CHECK-NEXT:    ret i8 [[R]]
+; CHECK-NEXT:    ret i8 undef
 ;
   %r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 %shamt)
   ret i8 %r
@@ -641,8 +640,7 @@ define i8 @fshl_ops_undef(i8 %shamt) {
 
 define i9 @fshr_ops_undef(i9 %shamt) {
 ; CHECK-LABEL: @fshr_ops_undef(
-; CHECK-NEXT:    [[R:%.*]] = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 [[SHAMT:%.*]])
-; CHECK-NEXT:    ret i9 [[R]]
+; CHECK-NEXT:    ret i9 undef
 ;
   %r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 %shamt)
   ret i9 %r
@@ -652,8 +650,7 @@ define i9 @fshr_ops_undef(i9 %shamt) {
 
 define i8 @fshl_shift_undef(i8 %x, i8 %y) {
 ; CHECK-LABEL: @fshl_shift_undef(
-; CHECK-NEXT:    [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 undef)
-; CHECK-NEXT:    ret i8 [[R]]
+; CHECK-NEXT:    ret i8 [[X:%.*]]
 ;
   %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 undef)
   ret i8 %r
@@ -661,8 +658,7 @@ define i8 @fshl_shift_undef(i8 %x, i8 %y
 
 define i9 @fshr_shift_undef(i9 %x, i9 %y) {
 ; CHECK-LABEL: @fshr_shift_undef(
-; CHECK-NEXT:    [[R:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 undef)
-; CHECK-NEXT:    ret i9 [[R]]
+; CHECK-NEXT:    ret i9 [[Y:%.*]]
 ;
   %r = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 undef)
   ret i9 %r




More information about the llvm-commits mailing list