[llvm] [NVPTX] Add support for clamped funnel shift intrinsics (PR #113228)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 15:54:20 PDT 2024
================
@@ -384,6 +393,22 @@ static Instruction *simplifyNvvmIntrinsic(IntrinsicInst *II, InstCombiner &IC) {
return BinaryOperator::Create(
Instruction::FDiv, ConstantFP::get(II->getArgOperand(0)->getType(), 1),
II->getArgOperand(0), II->getName());
+
+ case SCP_FunnelShiftClamp: {
+ // Canoncialize a clamping funnel shift to the generic llvm funnel shift
+ // when possible, as this is easier for llvm to optimize further.
+ if (const auto *ShiftConst = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
+ if (ShiftConst->getZExtValue() >= II->getType()->getIntegerBitWidth())
+ return IC.replaceInstUsesWith(*II, II->getArgOperand(1));
----------------
Artem-B wrote:
Unless I'm mistaken, clamped shift right should've returned MSB bits, AKA `getArgOperand(0)`. See the test comment below.
https://github.com/llvm/llvm-project/pull/113228
More information about the llvm-commits
mailing list