llvm.org GIT mirror llvm / eaf8151
[InstSimplify] fold funnel shifts with undef operands Splitting these off from the D54666. Patch by: nikic (Nikita Popov) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347332 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 10 months ago
2 changed file(s) with 14 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
50415041 }
50425042 case Intrinsic::fshl:
50435043 case Intrinsic::fshr: {
5044 Value *ShAmtArg = ArgBegin[2];
5044 Value *Op0 = ArgBegin[0], *Op1 = ArgBegin[1], *ShAmtArg = ArgBegin[2];
5045
5046 // If both operands are undef, the result is undef.
5047 if (match(Op0, m_Undef()) && match(Op1, m_Undef()))
5048 return UndefValue::get(F->getReturnType());
5049
5050 // If shift amount is undef, assume it is zero.
5051 if (match(ShAmtArg, m_Undef()))
5052 return ArgBegin[IID == Intrinsic::fshl ? 0 : 1];
5053
50455054 const APInt *ShAmtC;
50465055 if (match(ShAmtArg, m_APInt(ShAmtC))) {
50475056 // If there's effectively no shift, return the 1st arg or 2nd arg.
631631
632632 define i8 @fshl_ops_undef(i8 %shamt) {
633633 ; CHECK-LABEL: @fshl_ops_undef(
634 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 [[SHAMT:%.*]])
635 ; CHECK-NEXT: ret i8 [[R]]
634 ; CHECK-NEXT: ret i8 undef
636635 ;
637636 %r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 %shamt)
638637 ret i8 %r
640639
641640 define i9 @fshr_ops_undef(i9 %shamt) {
642641 ; CHECK-LABEL: @fshr_ops_undef(
643 ; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 [[SHAMT:%.*]])
644 ; CHECK-NEXT: ret i9 [[R]]
642 ; CHECK-NEXT: ret i9 undef
645643 ;
646644 %r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 %shamt)
647645 ret i9 %r
651649
652650 define i8 @fshl_shift_undef(i8 %x, i8 %y) {
653651 ; CHECK-LABEL: @fshl_shift_undef(
654 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 undef)
655 ; CHECK-NEXT: ret i8 [[R]]
652 ; CHECK-NEXT: ret i8 [[X:%.*]]
656653 ;
657654 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 undef)
658655 ret i8 %r
660657
661658 define i9 @fshr_shift_undef(i9 %x, i9 %y) {
662659 ; CHECK-LABEL: @fshr_shift_undef(
663 ; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 undef)
664 ; CHECK-NEXT: ret i9 [[R]]
660 ; CHECK-NEXT: ret i9 [[Y:%.*]]
665661 ;
666662 %r = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 undef)
667663 ret i9 %r