if (SDI->getType()->isVectorTy())
return false;
+ ConstantRange LCR = LVI->getConstantRange(SDI->getOperand(0), SDI);
+ ConstantRange RCR = LVI->getConstantRange(SDI->getOperand(1), SDI);
+
+ if (LCR.abs().icmp(CmpInst::ICMP_ULT, RCR.abs())) {
+ SDI->replaceAllUsesWith(SDI->getOperand(0));
+ SDI->eraseFromParent();
+ return true;
+ }
+
struct Operand {
Value *V;
Domain D;
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[Y_CMP]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[AND_Y]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[AND_Y]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;