llvm.org GIT mirror llvm / ea9bcfc
ConstantFold: an undef shift amount results in undef X shifted by undef results in undef because the undef value can represent values greater than the width of the operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223968 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
2 changed file(s) with 35 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
950950 return C1;
951951 return Constant::getAllOnesValue(C1->getType()); // undef | X -> ~0
952952 case Instruction::LShr:
953 if (isa(C2) && isa(C1))
954 return C1; // undef lshr undef -> undef
955 return Constant::getNullValue(C1->getType()); // X lshr undef -> 0
956 // undef lshr X -> 0
953 // X >>l undef -> undef
954 if (isa(C2))
955 return C2;
956 // undef >>l X -> 0
957 return Constant::getNullValue(C1->getType());
957958 case Instruction::AShr:
958 if (!isa(C2)) // undef ashr X --> all ones
959 return Constant::getAllOnesValue(C1->getType());
960 else if (isa(C1))
961 return C1; // undef ashr undef -> undef
962 else
963 return C1; // X ashr undef --> X
959 // X >>a undef -> undef
960 if (isa(C2))
961 return C2;
962 // undef >>a X -> all ones
963 return Constant::getAllOnesValue(C1->getType());
964964 case Instruction::Shl:
965 if (isa(C2) && isa(C1))
966 return C1; // undef shl undef -> undef
967 // undef << X -> 0 or X << undef -> 0
965 // X << undef -> undef
966 if (isa(C2))
967 return C2;
968 // undef << X -> 0
968969 return Constant::getNullValue(C1->getType());
969970 }
970971 }
194194 %b = udiv i32 undef, 0
195195 ret i32 %b
196196 }
197
198 ; CHECK-LABEL: @test25
199 ; CHECK: ret i32 undef
200 define i32 @test25(i32 %a) {
201 %b = lshr i32 0, undef
202 ret i32 %b
203 }
204
205 ; CHECK-LABEL: @test26
206 ; CHECK: ret i32 undef
207 define i32 @test26(i32 %a) {
208 %b = ashr i32 0, undef
209 ret i32 %b
210 }
211
212 ; CHECK-LABEL: @test27
213 ; CHECK: ret i32 undef
214 define i32 @test27(i32 %a) {
215 %b = shl i32 0, undef
216 ret i32 %b
217 }