llvm.org GIT mirror llvm / ef654a7
[InstSimplify] Optimize away urems in the presence of range metadata We know that urem %V, C can be optimized away to %V if %V is ult C. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291282 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 2 years ago
3 changed file(s) with 49 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
12451245 unsigned MaxRecurse) {
12461246 if (Value *V = SimplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse))
12471247 return V;
1248
1249 // urem %V, C -> %V if %V < C
1250 if (MaxRecurse) {
1251 if (Constant *C = dyn_cast_or_null(SimplifyICmpInst(
1252 ICmpInst::ICMP_ULT, Op0, Op1, Q, MaxRecurse - 1))) {
1253 if (C->isAllOnesValue()) {
1254 return Op0;
1255 }
1256 }
1257 }
12481258
12491259 return nullptr;
12501260 }
None ; RUN: opt < %s -instcombine -S | grep "= or i32 %x, -5"
0 ; RUN: opt < %s -instcombine -S | FileCheck %s
11
2 @.str = internal constant [5 x i8] c"foo\0A\00" ; <[5 x i8]*> [#uses=1]
3 @.str1 = internal constant [5 x i8] c"bar\0A\00" ; <[5 x i8]*> [#uses=1]
2 @.str = internal constant [5 x i8] c"foo\0A\00"
3 @.str1 = internal constant [5 x i8] c"bar\0A\00"
44
55 define i32 @main() nounwind {
66 entry:
7 %x = call i32 @func_11( ) nounwind ; [#uses=1]
8 %tmp3 = or i32 %x, -5 ; [#uses=1]
9 %tmp5 = urem i32 251, %tmp3 ; [#uses=1]
10 %tmp6 = icmp ne i32 %tmp5, 0 ; [#uses=1]
11 %tmp67 = zext i1 %tmp6 to i32 ; [#uses=1]
12 %tmp9 = urem i32 %tmp67, 95 ; [#uses=1]
13 %tmp10 = and i32 %tmp9, 1 ; [#uses=1]
14 %tmp12 = icmp eq i32 %tmp10, 0 ; [#uses=1]
15 br i1 %tmp12, label %bb14, label %bb
7 %x = call i32 @func_11() nounwind
8 %tmp3 = or i32 %x, -5
9 %tmp5 = urem i32 251, %tmp3
10 %tmp6 = icmp ne i32 %tmp5, 0
11 %tmp67 = zext i1 %tmp6 to i32
12 %tmp9 = urem i32 %tmp67, 95
13 %tmp10 = and i32 %tmp9, 1
14 %tmp12 = icmp eq i32 %tmp10, 0
15 br i1 %tmp12, label %bb14, label %bb
1616
17 bb: ; preds = %entry
18 br label %bb15
17 bb:
18 br label %bb15
1919
20 bb14: ; preds = %entry
21 br label %bb15
20 bb14:
21 br label %bb15
2222
23 bb15: ; preds = %bb14, %bb
24 %iftmp.0.0 = phi i8* [ getelementptr ([5 x i8], [5 x i8]* @.str1, i32 0, i32 0), %bb14 ], [ getelementptr ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), %bb ] ; [#uses=1]
25 %tmp17 = call i32 (i8*, ...) @printf( i8* %iftmp.0.0 ) nounwind ; [#uses=0]
26 ret i32 0
23 bb15:
24 %iftmp.0.0 = phi i8* [ getelementptr ([5 x i8], [5 x i8]* @.str1, i32 0, i32 0), %bb14 ], [ getelementptr ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), %bb ]
25 %tmp17 = call i32 (i8*, ...) @printf(i8* %iftmp.0.0) nounwind
26 ret i32 0
2727 }
28
29 ; CHECK-LABEL: define i32 @main(
30 ; CHECK: call i32 @func_11()
31 ; CHECK-NEXT: br i1 false, label %bb14, label %bb
2832
2933 declare i32 @func_11()
3034
31 declare i32 @printf(i8*, ...) nounwind
35 declare i32 @printf(i8*, ...) nounwind
4848 %mod1 = urem i32 %mod, %n
4949 ret i32 %mod1
5050 }
51
52 declare i32 @external()
53
54 define i32 @rem4() {
55 ; CHECK-LABEL: @rem4(
56 ; CHECK: [[CALL:%.*]] = call i32 @external(), !range !0
57 ; CHECK-NEXT: ret i32 [[CALL]]
58 ;
59 %call = call i32 @external(), !range !0
60 %urem = urem i32 %call, 3
61 ret i32 %urem
62 }
63
64 !0 = !{i32 0, i32 3}