[PATCH] D54478: [InstCombine] fold funnel shift amount based on demanded bits

Fabian Giesen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 13 10:00:39 PST 2018


fabiang added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineCalls.cpp:1998
+    unsigned BitWidth = II->getType()->getScalarSizeInBits();
+    APInt Op2Demanded = APInt::getLowBitsSet(BitWidth, Log2_32_Ceil(BitWidth));
+    KnownBits Op2Known(BitWidth);
----------------
Need to check whether BitWidth is a power of 2 here, this is incorrect for non-pow2. Take the BitWidth=33 case in the tests below.

A mod-33 funnel shift by say 65 should shift by 65-33=32 not 65 % 64 = 1.


================
Comment at: test/Transforms/InstCombine/fsh.ll:46
 ; CHECK-LABEL: @fshr_mask_simplify1(
-; CHECK-NEXT:    [[MASKEDSH:%.*]] = and i33 [[SH:%.*]], 64
-; CHECK-NEXT:    [[R:%.*]] = call i33 @llvm.fshr.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 [[MASKEDSH]])
-; CHECK-NEXT:    ret i33 [[R]]
+; CHECK-NEXT:    ret i33 [[Y:%.*]]
 ;
----------------
Can't eliminate the AND here, the reduction mod 64 doesn't interact with the mod-33 funnel shift amount in a useful way. (That I can see.)


================
Comment at: test/Transforms/InstCombine/fsh.ll:57
 ; CHECK-LABEL: @fshl_mask_simplify2(
-; CHECK-NEXT:    [[MASKEDSH:%.*]] = and <2 x i31> [[SH:%.*]], <i31 32, i31 32>
-; CHECK-NEXT:    [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[Y:%.*]], <2 x i31> [[MASKEDSH]])
-; CHECK-NEXT:    ret <2 x i31> [[R]]
+; CHECK-NEXT:    ret <2 x i31> [[X:%.*]]
 ;
----------------
Same here.


https://reviews.llvm.org/D54478





More information about the llvm-commits mailing list