Skip to content

Commit 087ad0b

Browse files
committed
Call inst simplify for casts
1 parent cd6e6be commit 087ad0b

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ Instruction *InstCombinerImpl::commonCastTransforms(CastInst &CI) {
156156
Value *Src = CI.getOperand(0);
157157
Type *Ty = CI.getType();
158158

159-
if (auto *SrcC = dyn_cast<Constant>(Src))
160-
if (Constant *Res = ConstantFoldCastOperand(CI.getOpcode(), SrcC, Ty, DL))
161-
return replaceInstUsesWith(CI, Res);
159+
if (Value *Res =
160+
simplifyCastInst(CI.getOpcode(), Src, Ty, SQ.getWithInstruction(&CI)))
161+
return replaceInstUsesWith(CI, Res);
162162

163163
// Try to eliminate a cast of a cast.
164164
if (auto *CSrc = dyn_cast<CastInst>(Src)) { // A->B->C cast

llvm/test/Transforms/InstCombine/cast-set-preserve-signed-dbg-val.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ define i16 @test5(i16 %A) !dbg !34 {
1111
call void @llvm.dbg.value(metadata i32 %C, metadata !37, metadata !DIExpression()), !dbg !41
1212

1313
; Preserve the dbg.value for the DCE'd 32-bit 'and'.
14-
;
15-
; The high 16 bits of the original 'and' require sign-extending the new 16-bit and:
1614
; CHECK-NEXT: #dbg_value(i16 [[and]], [[C:![0-9]+]],
17-
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value)
15+
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value)
1816

1917
%D = trunc i32 %C to i16, !dbg !42
2018
call void @llvm.dbg.value(metadata i16 %D, metadata !38, metadata !DIExpression()), !dbg !42

llvm/test/Transforms/InstCombine/ptr-int-cast.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ define <4 x ptr> @test7(<4 x i128> %arg) nounwind {
8989

9090
define i64 @ptrtoint_gep_sub(ptr %ptr, i64 %end.addr) {
9191
; CHECK-LABEL: @ptrtoint_gep_sub(
92-
; CHECK-NEXT: [[PTR_ADDR:%.*]] = ptrtoint ptr [[PTR:%.*]] to i64
93-
; CHECK-NEXT: [[SIZE:%.*]] = sub i64 [[END_ADDR1:%.*]], [[PTR_ADDR]]
94-
; CHECK-NEXT: [[END:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[SIZE]]
95-
; CHECK-NEXT: [[END_ADDR:%.*]] = ptrtoint ptr [[END]] to i64
96-
; CHECK-NEXT: ret i64 [[END_ADDR]]
92+
; CHECK-NEXT: ret i64 [[END_ADDR:%.*]]
9793
;
9894
%ptr.addr = ptrtoint ptr %ptr to i64
9995
%size = sub i64 %end.addr, %ptr.addr

0 commit comments

Comments
 (0)