[PATCH] D119645: [Transforms] Fix a cast to Instruction if CreateLShr() returns a constant
Dmitry Vassiliev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 12 11:48:27 PST 2022
slydiman created this revision.
slydiman added reviewers: rampitec, nikic, asavonic, krisb.
slydiman added a project: LLVM.
Herald added a subscriber: hiraditya.
slydiman requested review of this revision.
Herald added a subscriber: llvm-commits.
When X is a constant, CreateLShr() returns a constant instead of an instruction.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119645
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3677,9 +3677,12 @@
APInt FoldConst = C1->getValue().lshr(C2->getValue());
FoldConst ^= C3->getValue();
// Prepare the two operands.
- auto *Opnd0 = cast<Instruction>(Builder.CreateLShr(X, C2));
+ Value *Opnd0 = Builder.CreateLShr(X, C2);
Opnd0->takeName(cast<Instruction>(Op0));
- Opnd0->setDebugLoc(I.getDebugLoc());
+ // When X is a constant, CreateLShr() returns a constant instead
+ // of an instruction.
+ if (Instruction *Opnd0Inst = dyn_cast<Instruction>(Opnd0))
+ Opnd0Inst->setDebugLoc(I.getDebugLoc());
return BinaryOperator::CreateXor(Opnd0, ConstantInt::get(Ty, FoldConst));
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119645.408206.patch
Type: text/x-patch
Size: 926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220212/d3eaceda/attachment.bin>
More information about the llvm-commits
mailing list