File tree 2 files changed +16
-1
lines changed
lib/Transforms/AggressiveInstCombine
test/Transforms/AggressiveInstCombine
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -396,7 +396,8 @@ void TruncInstCombine::ReduceExpressionDag(Type *SclTy) {
396
396
Res = Builder.CreateBinOp ((Instruction::BinaryOps)Opc, LHS, RHS);
397
397
// Preserve `exact` flag since truncation doesn't change exactness
398
398
if (Opc == Instruction::LShr)
399
- cast<Instruction>(Res)->setIsExact (I->isExact ());
399
+ if (auto *ResI = dyn_cast<Instruction>(Res))
400
+ ResI->setIsExact (I->isExact ());
400
401
break ;
401
402
}
402
403
case Instruction::Select: {
Original file line number Diff line number Diff line change @@ -234,3 +234,17 @@ define i16 @lshr_negative_operand_but_short(i16 %x) {
234
234
%trunc = trunc i32 %lshr2 to i16
235
235
ret i16 %trunc
236
236
}
237
+
238
+ ; We may encounter unoptimized IR as below,
239
+ ; so don't crash by assuming that we can
240
+ ; apply instruction flags (exact) if there
241
+ ; is no instruction.
242
+
243
+ define i8 @non_canonical_crash () {
244
+ ; CHECK-LABEL: @non_canonical_crash(
245
+ ; CHECK-NEXT: ret i8 8
246
+ ;
247
+ %sh = lshr i32 33 , 2
248
+ %tr = trunc i32 %sh to i8
249
+ ret i8 %tr
250
+ }
You can’t perform that action at this time.
0 commit comments